<?php
class CompanysController extends AppController{

     var $name='Companys';
     var $uses = array("Economics_state","User_msg_relationship","Msg","Attachment","User",
     					"CompInstitution","CompAchievement","Company","Project","Codetype","ProCvalue",
     					"Group","Followinfo","Constant","CompPerson","Codevalue",
                       "CompanyPatent","CompPage","DevelopmentCost","CompPerson","Achievement",
                       "CompEconomic","CompFinanc","CompTalent","CompTrackinfo","CompType",
                       "CompTechnology","Informationfrom",
                       "CompCarrierlease","CompDormitorylease","CompLearentbonus","CompResearchrentbonus",
                       "CompJobapply","CompFinacerelease","CompDemand","DevelopmentList",
                       "CompOtherdeclare","CompSupportFund","CompPersonNum","CompCarrierleases");     
     var $helpers=array('Pagination','Html','Javascript','Form','Fck','Str','Action','Accp');
     var $components = array ('Pagination');
     var $layout='hindex';
     var $useDbConfig ="default";
     
    //首页内容
    function index($sortBy="modified",$direction="asc"){
    	
    	$grouplist=$this->Group->getGroupList();
    	$this->Session->write("grouplist",$grouplist);
        $this->insert_eco_state();
        $no_post=$this->get_unpost();
        $no_check=$this->get_uncheck();
        $this->Session->delete('companyid');
        $this->Session->delete('companyname');
        
        $industrys=$this->Codetype->getCValues($this->Constant->Industry,"all");
        $this->set(compact('industrys'));
        
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/index/'.$sortBy.'/'.$direction;
        $urlcount=0;
        
        $where="";
        $keyword="";
        $industry="";
        
        if(!empty($_GET['industry'])){
            $industry=$_GET['industry'];
            $objpidlist=$this->ProCvalue->findAllByCvid($industry);
            $pidlist="";
            if($objpidlist){
                foreach ($objpidlist as $pid){
                    $pidlist.="'".$pid["ProCvalue"]["pid"]."',";
                }
            }
            $wheres=rtrim($pidlist,",");	
            if(empty($wheres)){
                $wheres=1;
            }
            $where="Company.id in (".$wheres.") and ";
        }
        if(!empty($_GET["inds_name"])){
        	$ind_id = $this->Company->getIndCompId($_GET["inds_name"]);
        	$objpidlist=$this->ProCvalue->findAllByCvid($ind_id);
            $pidlist="";
            if($objpidlist){
                foreach ($objpidlist as $pid){
                    $pidlist.="'".$pid["ProCvalue"]["pid"]."',";
                }
            }
            $wheres=rtrim($pidlist,",");	
            if(empty($wheres)){
                $wheres=1;
            }
            $where="Company.id in (".$wheres.") and ";
        	
        }
        
        if(!empty($_GET["source_name"])){
        	$ind_id = $this->Company->getCompIdBySource($_GET["source_name"]);
        	$objpidlist=$this->Informationfrom->findAllByCvid($ind_id);
            $pidlist="";
            if($objpidlist){
                foreach ($objpidlist as $pid){
                    $pidlist.="'".$pid["Informationfrom"]["pid"]."',";
                }
            }
            $wheres=rtrim($pidlist,",");	
            if(empty($wheres)){
                $wheres=1;
            }
            $where="Company.id in (".$wheres.") and ";
        	
        }        
        
        
        
        
        //未提交
        if(!empty($_GET['unpost'])){
            $unpost=$_GET['unpost'];
            $sqldate=explode('-',$unpost);
            $where="Economics_state.company_year='".$sqldate[0]."' and Economics_state.month ='".$sqldate[1]."' and Economics_state.is_post='0' ";
            $result=$this->Economics_state->findAll($where);
            $pidlist="";
            if($result){
                foreach ($result as $pid){
                    $pidlist.="'".$pid["Economics_state"]["cid"]."',";
                }
            }
            $wheres=rtrim($pidlist,",");
            if(empty($wheres)){
                $wheres=1;
            }
            $where="Company.id in (".$wheres.") and ";
        }
        //未审核
        if(!empty($_GET['uncheck'])){
            $uncheck=$_GET['uncheck'];
            $sqldate=explode('-',$uncheck);
            $where="CompEconomic.company_year='".$sqldate[0]."' and CompEconomic.month ='".$sqldate[1]."' and CompEconomic.state='0' ";
            $result=$this->CompEconomic->findAll($where);
            $pidlist="";
            if($result){
                foreach ($result as $pid){
                    $pidlist.="'".$pid["CompEconomic"]["cid"]."',";
                }
            }
            $wheres=rtrim($pidlist,",");
            if(empty($wheres)){
                $wheres=1;
            }
            $where="Company.id in (".$wheres.") and ";
        }
        
        /*企业产业化情况表 列表
         *
         * */
        if(!empty($_GET['OwnedCompany'])){
        	$OwnedCompany =explode(",", $_GET['OwnedCompany']);
        	//print_r($OwnedCompany);
        	$str="";
        	foreach ($OwnedCompany as $comp){
        		$str .="'".$comp."',"; 
        	}
				$str .="'1'";        	
        	
        	 $where.=" Company.id  in (".$str.") and "; 
        }
        
        
        
        
       	/*获取当前登录用户的groupid，
       	 * 若当前用户为管理员，执行原先的显示全部信息的方法
       	 * 若不为管理员，添加条件，只查询company信息中groupid匹配的数据*/
        $user = $this->Session->read('User');
        
        if(empty($_GET['group'])){
        	if(!$user['isadmin']){
        		if(!$user['isvisitor']){
				 $where.=" Company.groupid = '".$user['groupid']."' and ";     
        		}  		  		
        	}
        }else{
        	 $where.=" Company.groupid = '".$_GET['group']."' and ";
        	 $group_mod_id = $_GET['group'];
        	 $this->set(compact('group_mod_id'));
        }
        
        
        //echo $where;exit;
        if(!empty($_GET['keyword'])){
            $keyword=$_GET['keyword'];
            $where.="(Company.company_name like '%".urldecode($keyword)."%') and ";
        }
        $where.="Company.is_deleted='0'";
        $this->Company->unbindModel(array ('hasMany' => array ('pros_cvalue','CompType','Attachment'),
        'belongsTo' => array ('Logo')));
        $urlcount=$this->Company->findCount($where);
        
        if(!empty($_GET['keyword']) || !empty($_GET['industry'])){
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        $paging["total"]= $urlcount;
        $showpage=0;
        $companys=array();
        
        $sort="desc";
        $capitalsort=$sort;
        $regsort=$sort;
        $columncapital="";
        if($sortBy=="capital"){
            $columncapital=$this->Codetype->getcapital().',';
            if($direction=="desc"){
                $capitalsort="asc";
            }
        }
        if($sortBy=="reg_time"){
            if($direction=="desc"){
                $regsort="asc";
            }
        }
        $this->set(compact('capitalsort','regsort'));
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->Company->unbindModel(array ('hasMany' => array ('pros_cvalue','CompType','Attachment'),
            'belongsTo' => array ('Logo')));
            $order=$sortBy." ".$direction;
            $companys=$this->Company->findAll($where,"`Company`.`id`, `Company`.`company_name`, `Company`.`email`, `Company`.`reg_time`, `Company`.`capital`,$columncapital `Company`.`cap_type`, `Company`.`contact`, `Company`.`tel`, `Company`.`groupid`",$order,$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('all_companys','companys','showpage','keyword','industry','sortBy','direction','no_post','unpost','no_check','uncheck','grouplist'));
        
    }
    
    function change_economic_state(){
       // var_dump($_GET['id']);die;
        
        $datas=$this->User->findAllByCid($_GET['cid']);
        $users=array();
        foreach($datas as $data){
           $users[]=$data['User']['id'];
        }
       // var_dump($users);die;
        $this->CompEconomic->id=$_GET['id'];
        $this->CompEconomic->saveField('state',$_GET['state']);
        
        $econ=$this->CompEconomic->findById($_GET['id']);
        $str=$econ['CompEconomic']['company_year'].'年'.$econ['CompEconomic']['month'].'月';
        //var_dump($str);die;
                //    var_dump($_POST['boss_check']);die;
            $log_user = $this->Session->read('User');
            if($_GET['state']=='1'){
                $msg['subject']=$str.'经济情况修改审核通过';
                $msg['content']=$str.'经济情况修改审核通过';
            }else if($_GET['state']=='2'){
                $msg['subject']=$str.'经济情况修改驳回';
                $msg['content']=$str.'经济情况修改驳回';
            }
            
            $msg['is_readed']='1';
            $msg['owner_id']=$log_user['id'];
           
           // var_dump($users);die;
            if($this->Msg->save($msg)){
                
                foreach($users as $user){
            
                    $relationship['id_one']=$user;
                   // var_dump($_POST['msg_type']);die;
                    
                    
                    $relationship['relationship']='sys';
                  
                    
                    $relationship['id_two']=$this->Msg->id;  
                         
                    $this->User_msg_relationship->saveAll($relationship);               
                }
            }  

        
        $this->Session->setFlash('更改成功');
        $this->redirect($this->referer());
    }
    
    function get_economics_state(){
        $objpnames=array();
        
        $where="Company.is_deleted='0'";
        $companys=$this->Company->findAll($where);
        
        $companys_id=array();
        foreach($companys as $v){
            $companys_id[]=$v['Company']['id'];
        }
        $now_year=date('Y',time());
    }
    
    function insert_eco_state(){
        $where="Company.is_deleted='0'";
        $companys=$this->Company->findAll($where);
        
        $companys_id=array();
        foreach($companys as $v){
            $companys_id[]=$v['Company']['id'];
        }
        
        $now_year=date('Y',time());
      //  $now_year=2012;
        foreach($companys_id as $user){
            
            $where="Economics_state.company_year='".$now_year."' and Economics_state.month ='1' and  Economics_state.cid= '".$user."' ";
            $result=$this->Economics_state->findAll($where);
            if(!$result){
                $relationship['company_year']=$now_year;
    
                $relationship['cid']=$user;              
                for($i=1;$i<=12;$i++){
                    $relationship['month']=$i;
                    $this->Economics_state->saveAll($relationship);                  
                }
            }
            
            
          //  $relationship['cid']=$this->Msg->id;  
                 
                         
        }
    }
    
    function get_uncheck(){
        $sql = "select * from `comp_economics` AS `CompEconomic` where `state` ='0' group by `company_year`,`month` order by `company_year` desc,`month` desc";
        $un_c= $this->CompEconomic->query($sql);
        
        $result= array();
        foreach($un_c as $v){
            $result[$v['CompEconomic']['company_year']][]=$v['CompEconomic']['month'];
            //$result[]=
        }
        //var_dump($result);die;
        return $result;
    }
    
    function get_unpost(){
      /*  $objpnames=array();
        
        $where="Company.is_deleted='0'";
        $companys=$this->Company->findAll($where);
        
        $companys_id=array();
        foreach($companys as $v){
            $companys_id[]=$v['Company']['id'];
        }
        $now_year=date('Y',time());
        //var_dump($now_year);die;
        foreach($companys_id as $company_id){
            
            $objpname=$this->CompEconomic->findAll("CompEconomic.cid='".$company_id."' and CompEconomic.is_deleted='0'");
                if($objpname){
                    foreach($objpname as $v){
                        $objpnames[$company_id]['company_year'][]=$v['CompEconomic']['company_year'];
                        $objpnames[$company_id]['month'][]=$v['CompEconomic']['month'];
                    } 
                }else{
                   $objpnames[$company_id]['company_year'][]='';
                   $objpnames[$company_id]['month'][]=''; 
                } 
                  
                
            
            
        }
      // var_dump($objpnames);die;
        foreach($objpnames as $key=>$obj){
            
            for($stryear=2012;$stryear<=$now_year;$stryear++){
                
                if(!in_array($stryear,$obj['company_year'])){
                    //本年一次都没提交的年份对应的值为0
                        //$no_post[$key][$stryear]='0';
                }else{
                    for($strmonth=1;$strmonth<12;$strmonth++){
               
                        if(!in_array($strmonth,$obj['month'])){
                            $no_post[$key][$stryear][$strmonth]='0';
                        }
                    }  
                }
     
                
            }
        }
        //按一维键名是公司id,二维键名为年,返回公司没有提交材料的数组
        
        $id_ones=array();
        foreach ($no_post as $v){  

          $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串  
          $temp[] = $v;  
        }  
   // var_dump($new_one);
       
        $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组  
        foreach ($temp as $k => $v){  
            $com=explode(",",$v);
            $id_ones[$k]['name'] = $com[0];   //再将拆开的数组重新组装  
            $id_ones[$k]['id'] = $com[1];   //再将拆开的数组重新组装  
            
        }  
       // var_dump($no_post);die; 
        return $no_post;*/
        //$where="Economics_state.company_year='".$now_year."' and Economics_state.month ='1' and  Economics_state.cid= '".$user."' ";
        
        $sql = "select * from `economics_states` AS `Economics_state` where `is_post` ='0' group by `company_year`,`month` order by `company_year` desc,`month` desc";
        $un_c= $this->Economics_state->query($sql);
        
        $result= array();
        $y=date("Y");
        $m=date("m");
        foreach($un_c as $v){
        	$company_year=$v['Economics_state']['company_year'];
        	$month=$v['Economics_state']['month'];
        	$where="Economics_state.company_year='".$company_year."' and Economics_state.month ='".$month."' and Economics_state.is_post ='0'";
        	$objECount=$this->Economics_state->findCount($where);
        	if($objECount>0){
        		
        		if(strlen($month) == 1){
        			$month = "0".$month;
        		}
        		if(date('Y-m-01') >= date('Y-m-d',strtotime($company_year.'-'.$month.'-01'))){
            		$result[$company_year][]=$month;
        		}
        	}
        }
        return $result;
    }
    //显示融资情况
    function financ()
    {
        //$id = $this->Session->read('economicid');
        //$where="(CompFinanc.is_deleted='0' and CompFinanc.comp_econ_id='".$id."')";	
        $cid = $this->Session->read('companyid');
        $where="(CompFinanc.is_deleted='0' and CompFinanc.cid='".$cid."')";	
        $this->CompFinanc->unbindModel(array ('hasMany' => array ('Attachment')));
        $comp_financs=$this->CompFinanc->findAll($where);
        $this->set(compact('comp_financs','comp_economics'));
        
    }
    //删除融资情况
    function delfinancs($id)
    {
        $this->CompFinanc->id=$id;
        $this->CompFinanc->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delfinancs","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('融资情况删除成功');		
        $this->redirect(array('action' => 'financ'));
        
    }
    //编辑融资情况
    function editfinanc($id=null)
    {	
    	$this->set('allfinancs',$this->Codetype->getCValues("融资来源"));
        $attachments=array();
        if($id){
            $objCompFinanc = $this->CompFinanc->findById($id);
            $this->data =$objCompFinanc;
            $fin_time=$this->data["CompFinanc"]["fin_time"];
            if($fin_time){
                $this->data["CompFinanc"]["fin_time"]=date("Y-m-d",strtotime($fin_time));
            }
            $attachments=$objCompFinanc["Attachment"];
        }else{
            if (!empty($this->data)) {	
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompFinanc"]["cid"]=$companyid;					
                }
                //$economicid=$this->Session->read('economicid');
                //if($economicid){
                //	$this->data["CompFinanc"]["comp_econ_id"]=$economicid;
                //}				
                $this->CompFinanc->save($this->data);
                $pid=$this->data["CompFinanc"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompFinanc->getLastInsertId();				
                    $data=array("guid"=>$pid,"event"=>"addfinanc","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editfinanc","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }				
                $this->Session->setFlash('融资情况保存成功');	
                $id=$this->CompFinanc->id;
                $pid=$this->data["CompFinanc"]["id"];
                if(empty($pid)){
                    $pid=$this->CompFinanc->getLastInsertId();
                }			
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                        $objAttachment["Attachment"]["pid"] = $pid;
                        $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                        $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachment);
                        $this->Attachment->id=null;
                    }
                }					
                //$economicid=$this->Session->read('economicid');
                //$this->redirect(array('action' => 'showeconomic',$economicid));		
                $this->redirect(array('action' => 'financ'));				
            }
        }
        $this->set(compact('attachments','id'));  
    }
    function showfinanc($id)
    {
        $this->editfinanc($id);
    }
    //删除经济情况
    function deleconomics($id)
    {
        $this->CompEconomic->id=$id;
        $this->CompEconomic->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deleconomics","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('经济情况删除成功');
        $this->redirect(array('action' => 'economic'));
        
    }
    //显示经济情况某项具体
    function showeconomic($id)
    {		
        $this->editeconomic($id);
        $economic= $this->CompEconomic->read();
        //$where="(CompFinanc.is_deleted='0' and CompFinanc.comp_econ_id='".$id."')";	
        //$comp_financs=$this->CompFinanc->findAll($where);
        $comp_financs=array();
        $this->set(compact('comp_financs','economic'));
    }
    //编辑经济情况
    function editeconomic($id=null)
    {			
        $attachments=array();
        if($id){		
            $objCompEconomic= $this->CompEconomic->findById($id);				
            //$this->Session->write('economicid', $id);	
            $this->Session->write('economicyear', $objCompEconomic["CompEconomic"]["company_year"]);			
            $this->data =$objCompEconomic;					
            $attachments=$objCompEconomic["Attachment"];
        }else{
            if (!empty($this->data)) {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompEconomic"]["cid"]=$companyid;
                }
                
                $user=$this->Session->read('User');
               // var_dump($user);die;
               //通过人员类别来修改审核状态
               	  if($user['isadmin'] || $user['isgroupadmin'] ){
                        if(empty($this->data["CompEconomic"]["creater"])){
                            $this->data["CompEconomic"]["creater"] = $user["id"];
                        }
                 }
                $this->CompEconomic->save($this->data);	
                                                        
//                $pid=$this->data["CompEconomic"]["id"];				
//                App::import('Helper', 'Accp');
//                $accp = new AccpHelper();
//                if(empty($pid)){
//                    $pid=$this->CompEconomic->getLastInsertId();					
//                    $data=array("guid"=>$pid,"event"=>"addeconomic","usertype"=>"1");
//                    $isflag=$accp->accpalert($data);
//                }else{					
//                    $data=array("guid"=>$pid,"event"=>"editeconomic","usertype"=>"1");
//                    $isflag=$accp->accpalert($data);				
//                }								
                $this->Session->setFlash('经济情况保存成功');
                $id=$this->CompEconomic->id;
                $pid=$this->data["CompEconomic"]["id"];
                if(empty($pid)){
                    $pid=$this->CompEconomic->getLastInsertId();
                }			
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                        $objAttachment["Attachment"]["pid"] = $pid;
                        $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                        $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachment);
                        $this->Attachment->id=null;						
                    }
                }
                
               // $now_year=date('Y',time());
                
                    
                $relationship['company_year']=$this->data["CompEconomic"]["company_year"];
        
                $relationship['cid']=$companyid;              
                
                $relationship['month']=$this->data["CompEconomic"]["month"];       
                $this->Economics_state->updateAll(
                        array('Economics_state.is_post' => "'1'"),
                        array('Economics_state.company_year' => $relationship['company_year'],'Economics_state.month' =>$relationship['month'],'Economics_state.cid' =>$relationship['cid'])
                );  
                if(!empty($_REQUEST['boss_check'])){
                	$this->CompEconomic->id=$pid;
					$this->CompEconomic->saveField("state",0);
					$this->Session->setFlash('经济情况提交成功，等待审核中。。。');
                    $log_user = $this->Session->read('User');
                    $msg['subject']='本公司已修改企业经济情况,请核实';
                    $msg['content']='本公司已修改企业经济情况,请核实';
                    $msg['is_readed']='1';
                    $msg['owner_id']=$log_user['id'];
                    $where='';
                    $where.="User.cid is null and  ";
                    $where.="User.is_deleted='0'";
                    $objusers=$this->User->findAll($where);
                    
                    $users=array();
                    foreach($objusers as $objuser){
                        $users[]=$objuser['User']['id'];
                    }
                   // var_dump($users);die;
                    if($this->Msg->save($msg)){
                        
                        foreach($users as $user){
                    
                            $relationship['id_one']=$user;
                           // var_dump($_POST['msg_type']);die;
                            
                            
                            $relationship['relationship']='sys';
                          
                            
                            $relationship['id_two']=$this->Msg->id;  
                                 
                            $this->User_msg_relationship->saveAll($relationship);               
                        }
                    }  
                }
                
                    
                //$this->redirect(array('action' => 'showeconomic',$pid));	
                $this->redirect(array('action' => 'economic'));						
            }
//			$this->data["CompEconomic"]["state"]=0;
        }   
        $this->set(compact('attachments','id'));		
    }
    
	//审核通过/审核不通过
	function setreview($id,$state,$type){
		switch($type){
			case 'economic':	$this->CompEconomic->id=$id;
					         	$this->CompEconomic->saveField("state",$state);
					         	$this->Session->setFlash('审核操作成功');
					         	$this->redirect("/companys/editeconomic/".$id);	break;
					         	
			case 'pro':			$this->CompTechnology->id=$id;
					         	$this->CompTechnology->saveField("status",$state);
					         	$this->Session->setFlash('审核操作成功');
					         	$this->redirect("/companys/edittechnology/".$id);break;
		}
	}
    
    function checkyearmonth($stryear,$strmonth){
        $isflag=0;
        $cid = $this->Session->read('companyid');
        $objpname=$this->CompEconomic->findCount("CompEconomic.cid='".$cid."' and  
        CompEconomic.company_year='".$stryear."' and  
        CompEconomic.month='".$strmonth."' and CompEconomic.is_deleted='0'");
        if($objpname>0){
            $isflag=1;
        }
        print($isflag);
        exit();
    }
    
    
    //显示全体经济情况
    function economic(){	
        $id = $this->Session->read('companyid');
        //$this->Session->delete('economicid');
        $objuser=$this->Session->read('User');
        $userid=$objuser['id'];
        //debug($userid);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/economic/';	
        $urlcount=0;
        $where="";
        $where.="CompEconomic.is_deleted='0' and CompEconomic.cid= '".$id."'";
        $urlcount=$this->CompEconomic->findCount($where);
        $paging['total'] =$urlcount;
        $showpage=0;
        $comp_economics=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);	
            $this->CompEconomic->unbindModel(array ('hasMany' => array ('Attachment')));
            $comp_economics=$this->CompEconomic->findAll($where,null,"CompEconomic.modified desc",$limit, $page);
        if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('comp_economics','showpage','comp_financs','userid'));
    }
    function timeeconomics($id=null){
        //$this->Session->delete('economicid');
        $id = $this->Session->read('companyid');
        $company = $this->Company->findById($id);
        $where="";
        $where.="(CompEconomic.is_deleted='0' and CompEconomic.cid = '".$id."')";
        $comp_economics=$this->CompEconomic->findAll($where);
        $year_time = array();
        foreach($comp_economics as $comp_economic){	
             if($year_time){
                $year = $comp_economic["CompEconomic"]["company_year"];
                if(!in_array($year,$year_time)){
                 $year_time[] = $comp_economic["CompEconomic"]["company_year"];
                 }
               }else{
                $year_time[] = $comp_economic["CompEconomic"]["company_year"];
             }
        }
        sort($year_time);
        $timeeconomics = array();
        foreach ($year_time as $y){
        $timewhere = '';
        $timewhere.="(CompEconomic.is_deleted='0' and CompEconomic.cid = '".$id."' and CompEconomic.company_year like '".$y."%')";
        $timeeconomics[$y]=$this->CompEconomic->findAll($timewhere);
        }
        $this->set(compact('comp_economics','company','year_time','timeeconomics'));
    }
    function dels($id,$email)
    {
        $this->Company->id=$id;
        $this->Company->saveField("is_deleted","1");
        //$this->loadModel("User");
        //$this->User->delcompanyuser($id);
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delcompany","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        
        //删除accp用户
        $objusers=$this->Session->read('AllUserList');
        $email=base64_decode($email);
        classRegistry::init("Company")->deleteAccpUser($objusers,$accp,$email);
        
        //删除和公司关联的表的数据
        classRegistry::init("Company")->delRelatedToCompany($id);
        
        $this->Session->setFlash('企业删除成功');
        $this->redirect(array('action' => 'index'));
    }
    function checkusermail($obj,$accp,$index){
        $email="";
        $umail="";
        if($index=="comapny"){
            $email=$obj["Company"]["email"];
        }
        if($index=="comapnyuser"){
            $email=$obj["CompPerson"]["email"];
        }
        $umail=$obj["User"]["uemail"];
        
        $flag=true;
        if($umail!=""){
            if($email!=$umail){
                $flag=true;
            }else{
                $flag=false;
            }
        }
    }
    
    function checkonlymail($nowmail,$cid){
    	$flag = true;
    	$emails = $this->User->findAll("User.is_deleted = '0'","email");
    	//debug($cid);exit;
    	if($cid){
    		$oldemail = $this->User->find("User.is_deleted = '0' and User.cid='".$cid."'","email");
	    	if($nowmail != $oldemail['User']['email']){
	    		foreach ($emails as $email){
	    			if($nowmail == $email['User']['email']){
	    				$flag = false;
	    				break;
	    			}
	    		}
	    	}
    	}else{
    		foreach ($emails as $email){
    			if($nowmail == $email['User']['email']){
    				$flag = false;
    				break;
    			}
    		}
    	}
    	
    	if(!$flag){
	    	$this->Session->setFlash('邮箱已经注册过','default',array('class' => 'info_error_alert'));
	        $this->redirect($this->referer());
	        exit();
    	}
    }
    
    function editinfo($id=null){
        $educations=$this->Constant->Education;
        unset($educations[1]);
        $this->set(compact('educations'));
        $industrys=$this->Codetype->getCValues($this->Constant->Industry,1);//所属产业
        $ctypes=$this->Codetype->getCValues($this->Constant->Companytype,1);//企业类型
    
        
        $informations = $this->Codetype->getCValues($this->Constant->InformationFrom,1);//信息来源
		$support_funds = $this->Codetype->getCValues("扶持金");
        
        $this->set(compact('industrys','ctypes','informations','support_funds'));
        $pros_cvalues=array();
        $companytypes=array();
        $informationfroms = array();
        $attachments=array();
        $logo=array();
        if($id)
        {
            $objcompany=$this->Company->findById($id);
            if(empty($objcompany)){
                $this->redirect('/users/login');
                exit();
            }
            $this->Session->write('companyid', $id);
            $this->Session->write('companyname', $objcompany["Company"]["company_name"]);
            $where="CompPage.cid='$id' and CompPage.is_deleted='0'";
            $comppage=$this->CompPage->findAll($where,"CompPage.id");
            if($comppage){
                $this->Session->write('cpid', $comppage[0]["CompPage"]["id"]);
            }else{
                $this->Session->write('cpid', '');
            }
            $where="CompTrackinfo.cid='$id'";
            $comptrackinfo=$this->CompTrackinfo->findAll($where,"CompTrackinfo.id");
            if($comptrackinfo){
                $this->Session->write('trackid', $comptrackinfo[0]["CompTrackinfo"]["id"]);
            }else{
                $this->Session->write('trackid', '');
            }
            $this->data=$objcompany;
            $pros_cvalues=$objcompany["pros_cvalue"];//在Company的Model中定义了三个表和Compay表的关系
            $companytypes=$objcompany["CompType"];
            
            $informationfroms = $objcompany['Informationfrom'];
            $attachments=$objcompany["Attachment"];
            $logo=$objcompany["Logo"];
            $CompSupportFunds = $objcompany['CompSupportFund'];
            
            $reg_time=$this->data["Company"]["reg_time"];
            if($reg_time){
                $this->data["Company"]["reg_time"]=date("Y-m-d",strtotime($reg_time));
            }
            $resident_time=$this->data["Company"]["resident_time"];
            if($resident_time){
                $this->data["Company"]["resident_time"]=date("Y-m-d",strtotime($resident_time));
            }
        }else{
        	
            if(!empty($this->data)){
                
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                $this->checkusermail($this->data,$accp,"comapny");
                $this->checkonlymail($this->data["Company"]["email"],$this->data['Company']['id']);
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                if(!empty($_FILES['CompanyLogo'])){
                    $uploads=$_FILES['CompanyLogo'];
                    $dirpath="upload/files/";
                    if($uploads["name"][0]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,0,1);
                        $objAttachments["Attachment"]["file_name"] = $uploads["name"][0];
                        $objAttachments["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachments);
                        $aids=$this->Attachment->getLastInsertId();
                        $this->data["Company"]["company_logo"]=$aids;
                        $this->Attachment->id=null;
                    }
                }
                if(empty($this->data["Company"]["capital"])){
                    $this->data["Company"]["capital"]=0;
                }
                if(empty($this->data["Company"]["size"])){
                    $this->data["Company"]["size"]=0;
                }
                $reg_time=$this->data["Company"]["reg_time"];
                if(empty($reg_time)){
                    $this->data["Company"]["reg_time"]=null;
                }
                $resident_time=$this->data["Company"]["resident_time"];
                if(empty($resident_time)){
                    $this->data["Company"]["resident_time"]=null;
                }
                $birthday=$this->data["Company"]["birthday"];
                if(empty($birthday)){
                    $this->data["Company"]["birthday"]=null;
                }
                if(empty($this->data["Company"]["id"])){
                    $objuser=$this->Session->read('User');
                    $userid=$objuser['id'];
                    $this->data["Company"]["first_owner"]=$userid;
                    /*获取当前登录用户的groupid，保存进company的groupid字段中*/
                    $usergroupid = $objuser['groupid'];
                    $this->data["Company"]["groupid"]=$usergroupid;
                }
                if(empty($this->data["Company"]["usualcontact"])){
                    $this->data["Company"]["usualcontact"]=null;
                }
                if(empty($this->data["Company"]["usualtel"])){
                    $this->data["Company"]["usualtel"]=0;
                }
                if(empty($this->data["Company"]["usualemail"])){
                    $this->data["Company"]["usualemail"]=null;
                }
                if(empty($this->data["Company"]["license_address"])){
                    $this->data["Company"]["license_address"]=null;
                }
                if(empty($this->data["Company"]["corporation_ID"])){
                    $this->data["Company"]["corporation_ID"]=null;
                }
                if(empty($this->data["Company"]["passportNo"])){
                    $this->data["Company"]["passportNo"]=null;
                }
                
                $objcompany=$this->Company->save($this->data);
                $name=$objcompany["Company"]["company_name"];
            
                $pid=$this->data["Company"]["id"];
                $this->Session->write('companyid', $pid);
                $this->Session->write('companyname', $name);
                
                $contact=$objcompany["Company"]["contact"];
                $email=$objcompany["Company"]["email"];
                $address="";
                $tel=$objcompany["Company"]["tel"];
                if(empty($pid)){
                    $pid=$this->Company->getLastInsertId();
                    $groupid=$this->Constant->CompanyGroupId;
                    $this->User->addcompanyuser($pid,$contact,$email,$address,$tel,null);
                }else{
                    $comp_user = $this->User->find("User.cid='".$pid."' and User.is_deleted='0'");
                    $this->User->addcompanyuser($pid,$contact,$email,$address,$tel,$comp_user['User']['id']);
                    //清空所属产品，企业类型，信息来源,扶持金的原有数据
                    $this->ProCvalue->deleteAll("pid='".$pid."'");
                    $this->CompType->deleteAll("cid='".$pid."'");
                    $this->Informationfrom->deleteAll("pid='".$pid."'");
                    $this->CompSupportFund->deleteAll("cid='".$pid."'");
                    $data=array("guid"=>$pid,"event"=>"editcompany","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }
                $this->Session->setFlash('企业保存成功');
  
                //扶持金保存
                $CSFcapital = $_REQUEST['capital'];
                $CSFhascashed = $_REQUEST['hascashed'];
                $CSFtype_id = $_REQUEST['type_id'];
                $CSFlength = count($CSFtype_id);
                $CSFvalues = array();
                for ($i=0; $i<$CSFlength; $i++){
                	$CSFvalues['CompSupportFund']['cid'] = $pid;
                	$CSFvalues['CompSupportFund']['type_id'] = $CSFtype_id[$i];
                	$CSFvalues['CompSupportFund']['capital'] = $CSFcapital[$i];
                	$CSFvalues['CompSupportFund']['hascashed'] = $CSFhascashed[$i];
                	$this->CompSupportFund->save($CSFvalues);
                	$this->CompSupportFund->id=null;
                }
                //所属产业
                $industryids=$this->data["Project"]["industryid"];
                if($industryids){
                    $objindustrys=explode(",",$industryids);
                    $objindustrys=array_unique($objindustrys);
                    $proscvalue=array();
                    foreach($objindustrys as $industry){
                        if($industry){
                            $proscvalue["ProCvalue"]["pid"]=$pid;
                            $proscvalue["ProCvalue"]["cvid"]=$industry;
                            $this->ProCvalue->save($proscvalue);
                            $this->ProCvalue->id=null;
                        }
                    }
                }
                //企业类型
                $companytypeids=$this->data["Project"]["companytypeid"];
                if($companytypeids){
                    $objcompanytypes=explode(",",$companytypeids);
                    $objcompanytypes=array_unique($objcompanytypes);
                    $comptype=array();
                    foreach($objcompanytypes as $cptype){
                        if($cptype){
                            $comptype["CompType"]["cid"]=$pid;
                            $comptype["CompType"]["cvid"]=$cptype;
                            $this->CompType->save($comptype);
                            $this->CompType->id=null;
                            
                        }
                    }
                }
                //信息来源
				$informationfromids=$this->data["Project"]["informationfromid"];
            	if($informationfromids){
            	    $objinformationfroms=explode(",",$informationfromids);
            	    $objinformationfroms=array_unique($objinformationfroms);
            	    $info = array();
            	    foreach($objinformationfroms as $information){
            	        if($information){
            	            $info["Informationfrom"]["pid"]=$pid;
            	            $info["Informationfrom"]["cvid"]=$information;
            	            $this->Informationfrom->save($info);
            	            $this->Informationfrom->id=null;
            	        }
            	    }
            	}
                if(!empty($_FILES['upload'])){
                    $uploads=$_FILES['upload'];
                    $name=$_FILES['upload']['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i]){
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $pid;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
                $cid=$this->data["Company"]["id"];
                $this->Session->write('companyid', $cid);
                $this->Session->write('companyname',$this->data["Company"]["company_name"]);
                if(empty($cid)){
                        $cid=$this->Company->getLastInsertId();
                        $this->Session->write('companyid', $cid);
                        $this->Session->write('companyname',$this->data["Company"]["company_name"]);
                        $this->quote($id);
                    }else{
                        $this->quote($id);
                    }
            }
            $this->data["Company"]["cap_type"]="0";
            $this->data["Company"]["is_height"]="0";
            $this->data["Company"]["is_funds"]="1";
            $this->data["Company"]["sex"]="0";
        }
        $this->set(compact('pros_cvalues','companytypes','informationfroms','attachments','logo','id','comptalents','filetypes','CompSupportFunds'));
    }
    
        function quote($id){		
            if($this->data["Company"]["person"]){					
                    $this->redirect(array('action' => 'editperson'));			
                }
                else if($this->data["Company"]["patents"]){
                    $this->redirect(array('action' => 'editpatent'));
                }				
                else if($this->data["Company"]["economic"]){
                    $this->redirect(array('action' => 'editeconomic'));
                }	
                else if($this->data["Company"]["patents"]){
                    $this->redirect(array('action' => 'editpatent'));
                }
                else if($this->data["Company"]["talent"]){
                    $this->redirect(array('action' => 'edittalent'));
                }					
                $user=$this->Session->read('User');
                if($user['cid']){
                $this->redirect(array('action' => 'showinfo',$user['cid']));
                }else{
                $this->redirect(array('action' => '/index'));
            }			
        }
    
    function checkcname($cname)
    {
        $isflag=0;
        $objcname=array();
        $objcname=$this->Company->findCount("Company.company_name='".urldecode($cname)."' and Company.is_deleted='0'");
        if($objcname>0){
            $isflag=1;
        }
        print($isflag);
        exit();
    }
    
    function showinfo()
    {
    	$compayid=$this->Session->read('companyid');
        $this->editinfo($compayid);
    }
    function showinfosummary($id){
    	$this->getpersoncount($id);
    	$this->getpatentcount($id);
    	
        $industrys=$this->Codetype->getCValues($this->Constant->Industry,1);//所属产业
        $ctypes=$this->Codetype->getCValues($this->Constant->Companytype,1);//企业类型
        $informations = $this->Codetype->getCValues($this->Constant->InformationFrom,1);//信息来源
        $this->set(compact('industrys','ctypes','informations'));
        
        $pros_cvalues=array();
        $companytypes=array();
        $attachments=array();
        $logo=array();
        if($id)
        {	
            $objcompany=$this->Company->findById($id);
            $compeconomic = $this->CompEconomic->findAll("CompEconomic.is_deleted='0' 
            												and CompEconomic.cid='".$id."' 
            												and CompEconomic.company_year='".date('Y')."' ",
            												'CompEconomic.general_income,CompEconomic.month',
            												'order by CompEconomic.month asc');	
            if(empty($objcompany)){
                $this->redirect('/users/login');
                exit();
            }
            $this->Session->write('companyid', $id);
            $this->Session->write('companyname', $objcompany["Company"]["company_name"]);
            $where="CompPage.cid='$id' and CompPage.is_deleted='0'";
            $comppage=$this->CompPage->findAll($where,"CompPage.id");
            if($comppage){
                $this->Session->write('cpid', $comppage[0]["CompPage"]["id"]);
            }else{
                $this->Session->write('cpid', '');
            }
            $where="CompTrackinfo.cid='$id'";
            $comptrackinfo=$this->CompTrackinfo->findAll($where,"CompTrackinfo.id");
            if($comptrackinfo){
                $this->Session->write('trackid', $comptrackinfo[0]["CompTrackinfo"]["id"]);
            }else{
                $this->Session->write('trackid', '');
            }
            $this->data=$objcompany;
            $pros_cvalues=$objcompany["pros_cvalue"];//所属产业
            $companytypes=$objcompany["CompType"];//企业类型
            $informationfroms = $objcompany['Informationfrom'];//信息来源
            $attachments=$objcompany["Attachment"];//附件
            $logo=$objcompany["Logo"];
            $reg_time=$this->data["Company"]["reg_time"];
        }
        $persontypes=$this->Codetype->getCValues("企业人员数");//获取人员类型
		$personnums = $this->CompPersonNum->findAllByCid($id);//获取人员类型对应的人数
        $this->set(compact('pros_cvalues','companytypes','informationfroms','attachments','logo','id','compeconomic','persontypes','personnums'));
    
    }
    function showtalentdb($id,$cid,$cname){
        $this->Session->write('companyid', $cid);
        $this->Session->write('companyname', $cname);
        $where="CompPage.cid='$cid' and CompPage.is_deleted='0'";
        $comppage=$this->CompPage->findAll($where,"CompPage.id");
        if($comppage){
            $this->Session->write('cpid', $comppage[0]["CompPage"]["id"]);
        }else{
            $this->Session->write('cpid', '');
        }
        $where="CompTrackinfo.cid='$id'";
        $comptrackinfo=$this->CompTrackinfo->findAll($where,"CompTrackinfo.id");
        if($comptrackinfo){
            $this->Session->write('trackid', $comptrackinfo[0]["CompTrackinfo"]["id"]);
        }else{
            $this->Session->write('trackid', '');
        }
        $this->redirect(array('action' => 'showtalent',$id));
    }
    function getpersoncount($compayid)
    {
        $educations=$this->Constant->Education;
        $educationcount=array();
        $personcount=0;
        $postgradutate_count=0;
        $i=0;
        foreach ($educations as $key=>$education)
        {
            $where="CompPerson.education='$key'";
            if($compayid){
                $where.=" and CompPerson.cid='$compayid'";
            }
            $where.=" and CompPerson.is_deleted='0'";
            $count=$this->CompPerson->findCount($where);
            $educationcount[$i]["key"]=$key;
            $educationcount[$i]["count"]=$count;
            $educationcount[$i]["name"]=$education;
            $i++;
            if($key == "2" || $key == "3")
            {
                $postgradutate_count += $count; //统计博士，硕士的总人数
            }
            $personcount+=$count;
        }
        $persontypes=$this->Constant->Persontype;
        $persontypecount=array();
        $i=0;
        foreach ($persontypes as $key=>$persontype)
        {
            $where="CompPerson.$key='1'";
            if($compayid){
                $where.=" and CompPerson.cid='$compayid'";
            }
            $where.=" and CompPerson.is_deleted='0'";
            $count=$this->CompPerson->findCount($where);
            $persontypecount[$i]["key"]=$key;
            $persontypecount[$i]["count"]=$count;
            $persontypecount[$i]["name"]=$persontype;
            $i++;
        }
        
        $this->set(compact('educationcount','personcount','persontypecount','postgradutate_count'));
    }
    function person($slsy = false)
    {
        $compayid=$this->Session->read('companyid');
        $this->getpersoncount($compayid);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/person/';
        $urlcount=0;
        $where="";
        $keyword="";
        
        if(!empty($_GET['education'])){
            if($_GET['education'] == "1")
                $where .= "CompPerson.education in('2','3') and ";
            else 
                $where.="CompPerson.education='".$_GET['education']."' and ";
        }
        if(!empty($_GET['persontype'])){
            $where.="CompPerson.".$_GET['persontype']."='1' and ";
        }
        if(!empty($_GET['keyword'])){
            $keyword=$_GET['keyword'];
            $where.="(CompPerson.person_name like '%".urldecode($keyword)."%') and ";
        }
        $where.="CompPerson.is_deleted='0'";
        
        if($compayid){
            $where.=" and CompPerson.cid='$compayid'";
        }
        $urlcount=$this->CompPerson->findCount($where);
        
        //若$slsy为true,则添加where条件，只查找有社保编号的person
        if ($slsy){
        	$where .= "and CompPerson.socialsecurityID != '0'";
        }
        
        if(!empty($_GET['keyword']) || !empty($_GET['education']) || !empty($_GET['persontype'])){
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        $paging['total'] =$urlcount;
        $showpage=0;
        $persons=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $persons=$this->CompPerson->findAll($where,"`CompPerson`.`socialsecurityID`,`CompPerson`.`id`, `CompPerson`.`major`,`CompPerson`.`email`, `CompPerson`.`person_name`, `CompPerson`.`is_core`, `CompPerson`.`education`, `CompPerson`.`school`","CompPerson.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $persontypes=$this->Codetype->getCValues("企业人员数");//获取人员类型
		$personnums = $this->CompPersonNum->findAllByCid($compayid);//获取人员类型对应的人数
		
        $this->set(compact('persons','showpage','keyword','compayid','persontypes','personnums','slsy'));
    }
    function editperson($id=null, $slsy = false){
        $educations=$this->Constant->Education;
        unset($educations[1]);
        $contype=$this->Codetype->getCValues($this->Constant->Contype);
        $this->set(compact('educations','contype','id','slsy'));
        if(empty($id)){
            if(!empty($this->data)){
                if(empty($this->data["CompPerson"]["birthday"])){
                    $this->data["CompPerson"]["birthday"]=null;
                }
                if(empty($this->data["CompPerson"]["graduation_date"])){
                    $this->data["CompPerson"]["graduation_date"]=null;
                }
                if(empty($this->data["CompPerson"]["socialsecurityID"])){
                    $this->data["CompPerson"]["socialsecurityID"]='0';
                }                
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompPerson"]["cid"]=$companyid;
                }
                $this->CompPerson->save($this->data);
                $this->Session->setFlash('企业人员保存成功');
                if ($slsy){//填写了保险单号的信息，需要跳转到socialsecurity页面
                	$this->redirect(array('action' => 'socialsecurity'));
                }else{//未填写保险单号的信息，需要跳转到person页面
                	$this->redirect(array('action' => 'person'));
                }
            }
            $this->data["CompPerson"]["sex"]=1;
            $this->data["CompPerson"]["is_core"]=0;
            $this->data["CompPerson"]["is_technical"]=0;
            $this->data["CompPerson"]["is_rd"]=0;
            $this->data["CompPerson"]["is_stuoversea"]=0;
            $this->data["CompPerson"]["is_intern"]=0;
            $this->data["CompPerson"]["is_newgraduates"]=0;
            $this->data["CompPerson"]["is_contact"]=0;
        }else{
            $this->data=$this->CompPerson->findById($id);
            $birthday=$this->data["CompPerson"]["birthday"];
            if($birthday){
                $this->data["CompPerson"]["birthday"]=date("Y-m-d",strtotime($birthday));
            }
            $graduation_date=$this->data["CompPerson"]["graduation_date"];
            if($graduation_date){
                $this->data["CompPerson"]["graduation_date"]=date("Y-m-d",strtotime($graduation_date));
            }
        }
        
        $this->set(compact("slsy"));
    }
    
    function editssperson($id=null){
    	$slsy = true;
        $this->editperson($id,$slsy);
    }
    
    function delperson($id,$email)
    {
        $this->CompPerson->id=$id;		
        $this->CompPerson->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();		
        $data=array("guid"=>$id,"event"=>"delperson","usertype"=>"1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $isflag=$accp->accpalert($data);
        
        //删除accp用户
        $objusers=$this->Session->read('AllUserList');
        $email=base64_decode($email);
        classRegistry::init("Company")->deleteAccpUser($objusers,$accp,$email);
        
        $this->Session->setFlash('企业人员删除成功');
        $this->redirect(array('action' => 'person'));
    }
    
    function showperson($id, $slsy = false)
    {
        $this->editperson($id, $slsy);
    }
    function showssperson($id)
    {
    	$slsy = true;
        $this->showperson($id, $slsy);
    }
    /**
     * 显示添加具体的企业人员分类数的编辑页面
     */
    function showeditpersonnumpage($cid){
    	$this->redirect('/companys/editpersonnum/'.$cid);
    }
    /**
     * 添加具体企业人员分类数
     */
    function editpersonnum($cid = null){
    	if (empty($cid)){//执行编辑操作
    		$cid = $_REQUEST['companyid'];
	    	$this->CompPersonNum->deleteAll("cid='".$cid."'");//删除已存在的数据    	
	    	$personnums = $_REQUEST['personnum'];
	    	$type_ids = $_REQUEST['type_id'];
	    	$numlength = count($type_ids);
	    	$PNvalues = array();
	    	for ($i=0; $i<$numlength; $i++){
	    		$PNvalues['CompPersonNum']['cid'] = $cid;
	    		$PNvalues['CompPersonNum']['type_id'] = $type_ids[$i];
	    		$PNvalues['CompPersonNum']['number'] = $personnums[$i];
	    		$this->CompPersonNum->save($PNvalues);
	    		$this->CompPersonNum->id=null;
	    	}
	    	$this->redirect('/companys/person/');
    	}else{//显示编辑页面
			$persontypes=$this->Codetype->getCValues("企业人员数");//获取人员类型
			$personnums = $this->CompPersonNum->findAllByCid($cid);
	    	$this->set(compact('persontypes','personnums'));
    	}
    }
    
    /**
     * 
     * 在本公司缴纳社保的相关操作
     */	
    function socialsecurity()
    {
    	$slsy = true;
        $this->person($slsy);
    }
    function editsocialsecurity($id=null){
        $educations=$this->Constant->Education;
        unset($educations[1]);
        $contype=$this->Codetype->getCValues($this->Constant->Contype);
        $this->set(compact('educations','contype','id'));
        if(empty($id)){
            if(!empty($this->data)){
                if(empty($this->data["CompPerson"]["birthday"])){
                    $this->data["CompPerson"]["birthday"]=null;
                }
                if(empty($this->data["CompPerson"]["graduation_date"])){
                    $this->data["CompPerson"]["graduation_date"]=null;
                }
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompPerson"]["cid"]=$companyid;
                }
                $this->CompPerson->save($this->data);
                $this->Session->setFlash('企业人员保存成功');
                $this->redirect(array('action' => 'person'));
            }
            $this->data["CompPerson"]["sex"]=1;
            $this->data["CompPerson"]["is_core"]=0;
            $this->data["CompPerson"]["is_technical"]=0;
            $this->data["CompPerson"]["is_rd"]=0;
            $this->data["CompPerson"]["is_stuoversea"]=0;
            $this->data["CompPerson"]["is_intern"]=0;
            $this->data["CompPerson"]["is_newgraduates"]=0;
            $this->data["CompPerson"]["is_contact"]=0;
        }else{
            $this->data=$this->CompPerson->findById($id);
            $birthday=$this->data["CompPerson"]["birthday"];
            if($birthday){
                $this->data["CompPerson"]["birthday"]=date("Y-m-d",strtotime($birthday));
            }
            $graduation_date=$this->data["CompPerson"]["graduation_date"];
            if($graduation_date){
                $this->data["CompPerson"]["graduation_date"]=date("Y-m-d",strtotime($graduation_date));
            }
        }
    }
    function editpage($flag=null){
        $cpid=$this->Session->read('cpid');
        if(!empty($cpid) && empty($flag)){
            $this->Session->write('cpid',$cpid);
            $this->data=$this->CompPage->findById($cpid);
        }else{
            if(!empty($this->data)){
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompPage"]["cid"]=$companyid;
                }
                $objcomppage=$_POST;
                $comppages=array();
                foreach ($objcomppage as $key=>$comppage)
                {
                    if($key!="_method" && $key!="data" ){
                        $this->data["CompPage"][$key]=$_POST[$key];
                    }
                }
                $this->CompPage->save($this->data);
                $pid=$this->data["CompPage"]["id"];				
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompPage->getLastInsertId();					
                    $data=array("guid"=>$pid,"event"=>"addpage","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editpage","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }				
                $this->Session->setFlash('企业发展情况保存成功');
                if(empty($this->data["CompPage"]["id"])){
                    $cpid=$this->CompPage->getLastInsertId();
                }else{
                    $cpid=$this->data["CompPage"]["id"];
                }
                $this->Session->write('cpid',$cpid);
                
                $this->redirect(array('action' => 'editpage'));
            }
        }
        $this->set('id',$cpid);
    }
    function home($id,$eid)
    {
        $this->layout=null;
        $cpid=$this->Session->read('cpid');
        if($cpid){
            $id=$cpid;
        }
        $this->data=$this->CompPage->findById($id);
        $companyid=$this->Session->read('companyid');
        if($companyid){
            $companyid=$eid;
        }
        $objcompany=$this->Company->findById($eid);
        $logo=$objcompany["Logo"];
        $this->set(compact('logo'));
        $this->data=$objcompany;
    }
    //获取知识产权指标数
    function getpatentcount($companyid,$year=null)
    {
        $where="";
        $where.="(CompanyPatent.is_deleted='0' and CompanyPatent.cid = '".$companyid."'";
        if($year){
            $where.="and CompanyPatent.p_time like '".$year."%'";
        }
        $where.=")";
        $this->CompanyPatent->unbindModel(array ('hasMany' => array ('Attachment')));
        $patents=$this->CompanyPatent->findAll($where);
        $patenttype = array();
        $patentname = array();
        $patentstate = array('0','0','0','0');
        $i = 0;
        $j = 0;
        $k = 0;
        $m = 0;
        $patentname=$this->Codetype->getCValues($this->Constant->PatentType,1);
        $urlcount=0;
        while($i < 4)
        {
            foreach ($patentname as $key=>$paname){
                $cpcount=$this->CompanyPatent->findCount($where." and CompanyPatent.type_id='$key' and CompanyPatent.state='$i'");
                $patenttype[$i][$key] =$cpcount ;
                $urlcount+=$cpcount;
            }
            $i++;
        }
        $this->set(compact('patenttype','urlcount','patentname','patentstate'));
    }
//企业科技工作情况
    //删除
    function deltechnology($id){
        $this->CompTechnology->id=$id;
        $this->CompTechnology->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deltechnology","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('科技项目删除成功');
        $this->redirect('/companys/technology/1');
    }
    
    function gettechnologycount($companyid,$year=null) {
        $where="";
        $where.="(CompTechnology.is_deleted='0' and CompTechnology.cid = '".$companyid."'";
        if($year){
            $where.="and CompTechnology.p_time like '".$year."%'";
        }
        $where.=")";
        $this->CompTechnology->unbindModel(array ('belongsTo' => array ('type_id')));
        $urlcount=$this->CompTechnology->findCount($where);
        $this->CompTechnology->unbindModel(array ('hasMany' => array ('Attachment'),'belongsTo' => array ('type_id')));
        $technologies=$this->CompTechnology->findAll($where,"CompTechnology.state");
        $technologytype = array();
        $technologyname = array();
        $technologystate = array('0','0','0');
        foreach($technologyname as $key=>$tname){
            $technologytype[$key] =0 ;
        }
        foreach($technologies as $technology){
            if ($technology['CompTechnology']['state'] == '0' ){
                $technologystate['0'] += 1;
            }elseif (($technology['CompTechnology']['state'] == '1' )){
                $technologystate['1'] += 1;
            }elseif (($technology['CompTechnology']['state'] == '2' )){
                $technologystate['2'] += 1;
            }
       }
        $this->set(compact('technologytype','urlcount','technologyname','technologystate'));
    }
    //整体
    function technology($edit = null){
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);
        $types=$this->Codetype->getCValues($this->Constant->TechnologyReport);
        $charge=$this->Codetype->getCValues($this->Constant->Depart_Charge);
        $dstatus=$this->Codetype->getCValues($this->Constant->Declarate_Status,1);
        $id=$this->Session->read('companyid');
        $this->gettechnologycount($id);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/technology/';
        $urlcount=0;
        $where="";
//		$declaretype="";
        if(!empty($_GET['ptype'])){
            $where.="CompTechnology.type_id='".$_GET['ptype']."' and ";
        }
        if(isset($_GET['state'])){
            $where.="CompTechnology.state='".$_GET['state']."' and ";
        }	
        $where.="(CompTechnology.is_deleted='0' and CompTechnology.cid = '".$id."')";
        $this->CompTechnology->unbindModel(array ('belongsTo' => array ('type_id')));
        $urlcount=$this->CompTechnology->findCount($where);
        $paging['total'] =$urlcount;
        if (empty($edit)){
            if(!isset($_GET['ptype']) || !isset($_GET['state'])){
                $this->Session->setFlash('共检索出'.$urlcount.'条记录');
            }
        }
        $showpage=0;
        $technologies=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompTechnology->unbindModel(array ('hasMany' => array ('Attachment')));
            $technologies=$this->CompTechnology->findAll($where,
            "`CompTechnology`.`id`,`CompTechnology`.`state`,`CompTechnology`.`status`,`CompTechnology`.`apply_time`, `CompTechnology`.`accept_time`,`CompTechnology`.`department`,
             `CompTechnology`.`authorize_time`, `CompTechnology`.`tname`,`CompTechnology`.`creater`,`CompTechnology`.`declarate_status`,CompTechnology`.`type_id`","CompTechnology.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('technologies','showpage','charge','types','talstacktype','dstatus','userid'));
    }
    //编辑科技项目申报情况
    function edittechnology($id=null){
        $types=$this->Codetype->getCValues($this->Constant->TechnologyReport);
        $this->loadModel("Techstack");
        $obj=$this->Techstack->getValue(1);
        $this->set('alltechnologies',$obj);
        $attachments=array();
        if($id){
            if(empty($this->data)){
                $this->CompTechnology->id=$id;
                $technology = $this->CompTechnology->read();
                $attachments=$technology["Attachment"];
                $this->data = $technology;
                $apply_time=$this->data["CompTechnology"]["apply_time"];
                if($apply_time){
                $this->data["CompTechnology"]["apply_time"]=date("Y-m-d",strtotime($apply_time));
                }
                $accept_time=$this->data["CompTechnology"]["accept_time"];
                if($accept_time){
                $this->data["CompTechnology"]["accept_time"]=date("Y-m-d",strtotime($accept_time));
                }
                $authorize_time=$this->data["CompTechnology"]["authorize_time"];
                if($authorize_time){
                    $this->data["CompTechnology"]["authorize_time"]=date("Y-m-d",strtotime($authorize_time));
                }
            }
        }else{
            if (!empty($this->data)) {
                $status=$this->data["CompTechnology"]["state"];
                switch ($status){
                case "0":
                    $this->data["CompTechnology"]["accept_time"]=null;
                    $this->data["CompTechnology"]["authorize_time"]=null;
                    break;
                case "1":
                    $this->data["CompTechnology"]["authorize_time"]=null;
                    break;
                }
            
                $apply_time=$this->data["CompTechnology"]["apply_time"];
                if(empty($apply_time)){
                    $this->data["CompTechnology"]["apply_time"]=null;
                }
                $accept_time=$this->data["CompTechnology"]["accept_time"];
                if(empty($accept_time)){
                    $this->data["CompTechnology"]["accept_time"]=null;
                }
                $authorize_time=$this->data["CompTechnology"]["authorize_time"];
                if(empty($authorize_time)){
                    $this->data["CompTechnology"]["authorize_time"]=null;
                }
                
                $user=$this->Session->read('User');
                    //if($user['usertype']!='2' && $user['usertype']!='3'){
                        if(empty($this->data["CompTechnology"]["creater"])){
                        $this->data["CompTechnology"]["creater"] = $user["id"];
                    //}
                    //$this->data["CompTechnology"]["status"]=1;
                 }
                
                $this->CompTechnology->save($this->data);			
                $pid=$this->data["CompTechnology"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompTechnology->getLastInsertId();						
                    $data=array("guid"=>$pid,"event"=>"addtechnology","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"edittechnology","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }				
                $this->Session->setFlash('科技项目保存成功');
                $id=$this->CompTechnology->id;
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                    $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                    $objAttachment["Attachment"]["pid"] = $id;
                    $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                    $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                    $this->Attachment->save($objAttachment);
                    $this->Attachment->id=null;
                }
            }
            $edit = 1;//做了编辑或者添加后进行保存，控制提示信息
            $this->redirect('/companys/technology/'.$edit);
            }
//			$this->data["CompTechnology"]["status"]=0;
        }
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType);
        $statues=$this->Codetype->getCValues($this->Constant->Declarate_Status);		
        $this->set(compact('attachments','id','types','talstacktype','statues'));	
    }
    //显示
    function showtechnology($id=null){
        $this->edittechnology($id);
        $this->CompTechnology->id = $id;
        $talstack=$this->CompTechnology->findById($id);
        $technology = $this->CompTechnology->read();
        $company = $this->Company->findById($technology['CompTechnology']['cid']);
        $attachments ='';
        $attachments=$technology["Attachment"];
        $charge=$this->Codetype->getCValues($this->Constant->Depart_Charge);
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);	
        $this->set(compact('technology','attachments','company','talstack','charge','talstacktype'));
    }
    //按年度
    function timetechnology(){
        $id=$this->Session->read('companyid');
        $where="";
        $where.="(CompTechnology.is_deleted='0' and CompTechnology.cid = '".$id."')";
        $urlcount=$this->CompTechnology->findCount($where);
        $paging['total'] =$urlcount;
        $technologies=$this->CompTechnology->findAll($where);
        $year_time = array();
            foreach($technologies as $technology){	
             if($year_time){
             $year = date("Y",strtotime($technology["CompTechnology"]["created"]));
                if(!in_array($year,$year_time)){
                 $year_time[] = date("Y",strtotime($technology["CompTechnology"]["created"]));
                 }
               }else{
                $year_time[] = date("Y",strtotime($technology["CompTechnology"]["created"]));
               }
            }
            sort($year_time);
            $timetechnology = array();
            foreach ($year_time as $y){
            $timewhere = '';
            $timewhere.="(CompTechnology.is_deleted='0' and CompTechnology.cid = '".$id."' and CompTechnology.created like '".$y."%')";
            $timetechnology[$y]=$this->CompTechnology->findAll($timewhere);
            }
        $this->set(compact('technologies','showpage','year_time','timetechnology','urlcount'));
    }
    //知识产权指标首页
    function patents(){
        $id=$this->Session->read('companyid');
        $this->getpatentcount($id);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/patents/';
        $urlcount=0;
        $where="";
        
        if(isset($_GET['state']) && isset($_GET['ptype'])){
            $where.="CompanyPatent.type_id='".$_GET['ptype']."' and CompanyPatent.state='".$_GET['state']."' and ";
        }
        $where.="(CompanyPatent.is_deleted='0' and CompanyPatent.cid = '".$id."')";
        $this->CompanyPatent->unbindModel(array ('hasMany' => array ('Attachment')));
        $urlcount=$this->CompanyPatent->findCount($where);
        $paging['total'] =$urlcount;
        if(!empty($_GET['ptype']) || !empty($_GET['state'])){
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        $showpage=0;
        $patents=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompanyPatent->unbindModel(array ('hasMany' => array ('Attachment')));
            $patents=$this->CompanyPatent->findAll($where,null,"CompanyPatent.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('patents','showpage'));
        
    }
    
    function timepatents(){
        $id=$this->Session->read('companyid');
        $where="";
        $where.="(CompanyPatent.is_deleted='0' and CompanyPatent.cid = '".$id."')";
        $urlcount=$this->CompanyPatent->findCount($where);
        $paging['total'] =$urlcount;
        $this->CompanyPatent->unbindModel(array ('hasMany' => array ('Attachment')));
        $patents=$this->CompanyPatent->findAll($where);
        $year_time = array();
            foreach($patents as $patent){	
             if($year_time){
             $year = date("Y",strtotime($patent["CompanyPatent"]["created"]));
                if(!in_array($year,$year_time)){
                 $year_time[] = date("Y",strtotime($patent["CompanyPatent"]["created"]));
                 }
               }else{
                $year_time[] = date("Y",strtotime($patent["CompanyPatent"]["created"]));
               }
            }
            sort($year_time);
            $timepatents = array();
            foreach ($year_time as $y){
            $timewhere = '';
            $timewhere.="(CompanyPatent.is_deleted='0' and CompanyPatent.cid = '".$id."' and CompanyPatent.created like '".$y."%')";
            $this->CompanyPatent->unbindModel(array ('hasMany' => array ('Attachment')));
            $timepatents[$y]=$this->CompanyPatent->findAll($timewhere);
            }
        $objyear=$year_time;
        $objyears=array();
        $patentname=$this->Codetype->getCValues($this->Constant->PatentType,1);
        
        for($i=0;$i<count($objyear);$i++){
            $j = 0;
            $objyears[$i]["year"]=$objyear[$i];
            $urlcount=0;
            $patenttype=array();
            while($j < 4)
            {
                foreach ($patentname as $key=>$paname){
                    $cpcount=$this->CompanyPatent->findCount($where." and CompanyPatent.type_id='$key' and CompanyPatent.state='$j' and year(created)=$objyear[$i]");
                    $patenttype[$j][$paname] =$cpcount ;
                    $urlcount+=$cpcount;
                }
                $j++;
            }
            $objyears[$i]["type"]=$patenttype;
            $objyears[$i]["typecount"]=$urlcount;
        }
        $this->set(compact('showpage','objyears','timepatents','urlcount'));
        
    }
    //添加知识产权指标
    function editpatent($id=null){
    $this->set('allpatents',$this->Codetype->getCValues($this->Constant->PatentType));
    $attachments=array();
    if($id){
        if (empty($this->data)) {
            $this->CompanyPatent->id=$id;
            $patent = $this->CompanyPatent->read();
            $attachments=$patent["Attachment"];
            $this->data = $patent;
            $apply_time=$this->data["CompanyPatent"]["apply_time"];
            if($apply_time){
                $this->data["CompanyPatent"]["apply_time"]=date("Y-m-d",strtotime($apply_time));
            }
            $accept_time=$this->data["CompanyPatent"]["accept_time"];
            if($accept_time){
                $this->data["CompanyPatent"]["accept_time"]=date("Y-m-d",strtotime($accept_time));
            }
            $authorize_time=$this->data["CompanyPatent"]["authorize_time"];
            if($authorize_time){
                $this->data["CompanyPatent"]["authorize_time"]=date("Y-m-d",strtotime($authorize_time));
            }
            $buy_time=$this->data["CompanyPatent"]["buy_time"];
            if($buy_time){
                $this->data["CompanyPatent"]["buy_time"]=date("Y-m-d",strtotime($buy_time));	
            }
        }
     }else{
        if (!empty($this->data)) {
            $status=$this->data["CompanyPatent"]["state"];
            switch ($status){
                case "0":
                        $this->data["CompanyPatent"]["accept_time"]=null;
                        $this->data["CompanyPatent"]["authorize_time"]=null;
                        $this->data["CompanyPatent"]["buy_time"]=null;
                    break;
                case "1":
                        $this->data["CompanyPatent"]["authorize_time"]=null;
                        $this->data["CompanyPatent"]["buy_time"]=null;
                    break;
                case "2":
                        $this->data["CompanyPatent"]["buy_time"]=null;
                    break;
                case "3";
                        $this->data["CompanyPatent"]["apply_time"]=null;
                        $this->data["CompanyPatent"]["accept_time"]=null;
                        $this->data["CompanyPatent"]["authorize_time"]=null;					
                    break;
            }
            $to=$this->data["CompanyPatent"]["to"];
            if($to=="0"){
                $this->data["CompanyPatent"]["person_name"]=null;
            }
            $apply_time=$this->data["CompanyPatent"]["apply_time"];
            if(empty($apply_time)){
                $this->data["CompanyPatent"]["apply_time"]=null;
            }
            $accept_time=$this->data["CompanyPatent"]["accept_time"];
            if(empty($accept_time)){
                $this->data["CompanyPatent"]["accept_time"]=null;
            }
            $authorize_time=$this->data["CompanyPatent"]["authorize_time"];
            if(empty($authorize_time)){
                $this->data["CompanyPatent"]["authorize_time"]=null;
            }
            $buy_time=$this->data["CompanyPatent"]["buy_time"];
            if(empty($buy_time)){
                $this->data["CompanyPatent"]["buy_time"]=null;
            }
            $this->CompanyPatent->save($this->data);
            $pid=$this->data["CompanyPatent"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompanyPatent->getLastInsertId();					
                    $data=array("guid"=>$pid,"event"=>"addpatent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editpatent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
            $this->Session->setFlash('知识产权指标保存成功');
            $id=$this->CompanyPatent->id;
            App::import('Helper', 'Action');
            $actionf = new ActionHelper();
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                        $objAttachment["Attachment"]["pid"] = $id;
                        $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                        $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachment);
                        $this->Attachment->id=null;
                    }
                }
                $this->redirect('/companys/patents/');
        }
     }
     $this->set(compact('attachments','id'));
    }
    //显示知识产权指标
    function showpatent($id){
        $this->CompanyPatent->id = $id;
        $patent = $this->CompanyPatent->read();
        $company = $this->Company->findById($patent['CompanyPatent']['cid']);
        $attachments ='';
        $attachments=$patent["Attachment"];
        $this->set(compact('patent','attachments','company'));
    }
    //删除知识产权指标
    function delpatent($id){
        $this->CompanyPatent->id=$id;
        $this->CompanyPatent->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delpatent","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('知识产权指标删除成功');
        $this->redirect('/companys/patents/');
    }
    //编辑研发机构
    function editstitution($id=null){
    if(!empty($this->data)){
            $this->CompInstitution->save($this->data);
            $this->Session->setFlash('保存成功');
        $this->redirect("/companys/depcosts/");
        }
        if(!empty($id)){
            $this->data=$this->CompInstitution->findById($id);
        }
        $this->set(compact('id'));
    }
    //研发机构显示
    function showstitution($id){
        $this->editstitution($id);
    }
    //研发机构删除	
    function delstitution($id){ 
        $this->CompInstitution->id=$id;
        $this->CompInstitution->saveField("is_deleted","1");
        $this->Session->setFlash('研发机构删除成功');
        $this->redirect("/companys/depcosts/");
    }
    //显示产出和获奖成果数
    function showachieve($id){
        $this->editachieve($id);
    }
    //编辑产出和获奖成果数
    function editachieve($id=null){
        if(!empty($this->data)){
            $this->CompAchievement->save($this->data);
            $this->Session->setFlash('保存成功');
            $this->redirect("/companys/depcosts/");
        }
        if(!empty($id)){
            $this->data=$this->CompAchievement->findById($id);
        }
        $this->set(compact('id'));
    }
    //投入
    function timedepcosts()
    {
        $compayid=$this->Session->read('companyid');
        $where="(DevelopmentCost.is_deleted='0' and DevelopmentCost.cid = '".$compayid."')";
        $this->DevelopmentCost->unbindModel(array ('hasMany' => array ('Attachment')));
        $objyears=$this->DevelopmentCost->findAll($where,"distinct(year(c_time)) as c_time","c_time asc",null,null);
        $i=0;
        foreach ($objyears as $stryear){
            $c_time=$stryear[0]["c_time"];
            $wheres=$where." and year(DevelopmentCost.c_time)='".$c_time."'";
            $costs=$this->DevelopmentCost->findAll($wheres);
            $objyears[$i]["costs"]=$costs;
            $i++;
        }
        $this->set(compact('objyears'));
    }
    function depcosts(){
        $id=$this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/depcosts/';
        $urlcount=0;
        $where="";
        $where.="(DevelopmentCost.is_deleted='0' and DevelopmentCost.cid= '".$id."')";
        $urlcount=$this->DevelopmentCost->findCount($where);
        
        $paging['total'] =$urlcount;
        $showpage=0;
        $costs=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->DevelopmentCost->unbindModel(array ('hasMany' => array ('Attachment')));
            $costs=$this->DevelopmentCost->findAll($where,null,"DevelopmentCost.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
            $this->set(compact('costs','showpage'));
    
        $where="";
        $where.="(CompInstitution.is_deleted='0' and CompInstitution.cid= '".$id."')";
        $count_institution=$this->CompInstitution->findCount($where);
        $stitutions=$this->CompInstitution->findAll($where);
        $this->set(compact('count_institution','stitutions'));
        //产出、获奖成果
        $where="(CompAchievement.cid= '".$id."')";
        $achieves=$this->CompAchievement->findAll($where);
        if(empty($achieves)){
                $mp["CompAchievement"]["output_achievement"]="0";
                $mp["CompAchievement"]["award_achievement"]="0";
                $mp["CompAchievement"]["cid"]=$id;		    
                $this->CompAchievement->save($mp);
                $Achievementid=$this->CompAchievement->id;
        }else{
            $Achievementid=$achieves[0]["CompAchievement"]["id"];
        }
        $objachieves=$this->CompAchievement->findById($Achievementid);
        $this->set(compact('objachieves'));
    }
    //企业投入
    function editdepcost($id=null){
    $attachments =array();
    if($id){
        $this->Session->write('depcostid', $id);
        if (empty($this->data)) {
            $this->DevelopmentCost->id=$id;
            $cost= $this->DevelopmentCost->read();
            $attachments=$cost["Attachment"];
            $this->data = $cost;
        }
     }else{
        if (!empty($this->data)) {
            if(empty($this->data["DevelopmentCost"]["cost_type"])){
                $this->data["DevelopmentCost"]["cost_type"]=0;
             }
            $this->DevelopmentCost->save($this->data);
            $pid=$this->data["DevelopmentCost"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->DevelopmentCost->getLastInsertId();					
                    $data=array("guid"=>$pid,"event"=>"adddepcost","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editdepcost","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
            $this->Session->setFlash('研发费用投入保存成功');
            $id=$this->DevelopmentCost->id;
            App::import('Helper', 'Action');
            $actionf = new ActionHelper();
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                        $objAttachment["Attachment"]["pid"] = $id;
                        $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                        $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachment);
                        $this->Attachment->id=null;
                    }
                }	
                $this->redirect(array('action' => 'depcosts'));
        }
     }
        $this->set(compact('attachments','id'));
    }
    
    //研发费用显示
    function showdepcost($id){
        $this->editdepcost($id);
        //$this->DevelopmentCost->id = $id;
        $cost= $this->DevelopmentCost->read();
        $company = $this->Company->findById($cost['DevelopmentCost']['cid']);
        $attachments ='';
        $attachments=$cost["Attachment"];
        //研发投入清单
        $where="(DevelopmentList.is_deleted='0' and DevelopmentList.cid='".$cost['DevelopmentCost']['cid']."')";
        $lists=$this->DevelopmentList->findAll($where);	
        $this->set(compact('cost','attachments','company','lists'));
    }
    //研发费用删除
    function deldepcost($id){
        $this->DevelopmentCost->id=$id;
        $this->DevelopmentCost->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deldepcost","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('研发费用投入删除成功');
        $this->redirect('/companys/depcosts/');
    }
    //研发费用投入清单显示
    function deplist(){
        $companyid = $this->Session->read('companyid');
        $where="(DevelopmentList.is_deleted='0' and DevelopmentList.cid='".$companyid."')";	
        $this->DevelopmentList->unbindModel(array ('hasMany' => array ('Attachment')));
        $lists=$this->DevelopmentList->findAll($where);
        $this->set(compact('lists'));
    }
    
    function showdeplist($id){
        $this->editdeplist($id);
    }
    
    //研发费用投入清单编辑
    function editdeplist($id=null){
        $attachments=array();
        if($id){
            $objDeplist = $this->DevelopmentList->findById($id);
            $this->data = $objDeplist;
            $start_date = $this->data["DevelopmentList"]["start_date"];
            if($start_date){
                $this->data["DevelopmentList"]["start_date"] = date("Y-m-d",strtotime($start_date));
            }
            $finish_date = $this->data["DevelopmentList"]["finish_date"];
            if($finish_date){
                $this->data["DevelopmentList"]["finish_date"] = date("Y-m-d",strtotime($finish_date));
            }
            $attachments = $objDeplist["Attachment"];
        }else{
            if (!empty($this->data)) {	
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["DevelopmentList"]["cid"]=$companyid;					
                }
//		 		$depcostid = $this->Session->read("depcostid");
//				if($depcostid){
//					$this->data["DevelopmentList"]["cid"]=$depcostid;
//				}				
                $this->DevelopmentList->save($this->data);
                $pid=$this->data["DevelopmentList"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->DevelopmentList->getLastInsertId();				
                    $data=array("guid"=>$pid,"event"=>"adddeplist","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editdeplist","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }				
                $this->Session->setFlash('研发费用投入清单保存成功');	
                $id=$this->DevelopmentList->id;
                $pid=$this->data["DevelopmentList"]["id"];
                if(empty($pid)){
                    $pid=$this->DevelopmentList->getLastInsertId();
                }			
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                for($i=0;$i<count($name);$i++)
                {
                    $dirpath = "upload/files/";
                    if($uploads["name"][$i]){
                        $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                        $objAttachment["Attachment"]["pid"] = $pid;
                        $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                        $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachment);
                        $this->Attachment->id=null;
                    }
                }					
                $depcostid = $this->Session->read("depcostid");
                $this->redirect(array('action' => 'showdepcost',$depcostid));						
            }
        }
        $this->set(compact('attachments','id'));
    }
    //研发费用投入清单删除
    function deldeplist($id){
        $this->DevelopmentList->id=$id;
        $this->DevelopmentList->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deldeplist","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('研发费用投入清单删除成功');
        $this->redirect('/companys/deplist/');
    }
    //产学研合作情况
    function timeachievements()
    {
        $compayid=$this->Session->read('companyid');
        $where="(Achievement.is_deleted='0' and Achievement.cid = '".$compayid."')";
        $this->Achievement->unbindModel(array ('hasMany' => array ('Attachment')));
        $objyears=$this->Achievement->findAll($where,"distinct(year(a_time)) as a_time","a_time asc",null,null);
        $i=0;
        foreach ($objyears as $stryear){
            $a_time=$stryear[0]["a_time"];
            $wheres=$where." and year(Achievement.a_time)='".$a_time."'";
            $this->Achievement->unbindModel(array ('hasMany' => array ('Attachment')));
            $costs=$this->Achievement->findAll($wheres);
            $objyears[$i]["costs"]=$costs;
            $i++;
        }
        $this->set(compact('objyears'));
    }
    function achievements(){
        $id=$this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/achievements/';
        $urlcount=0;
        $id = $_SESSION['companyid'];
        $where="";
        $where.="(Achievement.is_deleted='0' and Achievement.cid= '".$id."')";
        $urlcount=$this->Achievement->findCount($where);
        $paging['total'] =$urlcount;
        $showpage=0;
        $achievements=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->Achievement->unbindModel(array ('hasMany' => array ('Attachment')));
            $achievements=$this->Achievement->findAll($where,null,"Achievement.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('achievements','showpage'));
    }
    //
    function editachievement($id=null){
    $attachments=array();
    if($id){
         if (empty($this->data)) {
         
             $this->Achievement->id=$id;
             $achievement= $this->Achievement->read();
             $attachments=$achievement["Attachment"];
             $this->data = $achievement;
         }
     }else{
        if (!empty($this->data)) {
            if(empty($this->data["Achievement"]["cost_type"])){
                $this->data["Achievement"]["cost_type"]=0;
            }
            if(empty($this->data["Achievement"]["a_time"])){
                $this->data["Achievement"]["a_time"]=null;
            }
            $this->Achievement->save($this->data);
            $pid=$this->data["Achievement"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->Achievement->getLastInsertId();						
                    $data=array("guid"=>$pid,"event"=>"addachievement","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editahievement","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
            $this->Session->setFlash('产学研合作情况保存成功');	
            $id=$this->Achievement->id;
            App::import('Helper', 'Action');
            $actionf = new ActionHelper();
                $uploads=$_FILES['upload'];
                $name=$_FILES['upload']['name'];
                if(!empty($name)){
                    for($i=0;$i<count($name);$i++)
                    {
                        $dirpath = "upload/files/";
                        if($uploads["name"][$i]){
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $id;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }
                }
                $this->redirect(array('action' => 'achievements'));
        }
        $this->data["Achievement"]["is_rely"]=0;
     }
     $this->set(compact('attachments','id'));
    }
    
    function showachievement($id){
        $this->editachievement ($id);
        $obj=$this->Achievement->findById($id);
        $this->data=$obj;
        $this->data["Achievement"]["a_time"]=date("Y-m-d",strtotime($obj["Achievement"]["a_time"]));
    }	
    
    function delachievement($id){
        $this->Achievement->id=$id;
        $this->Achievement->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delachievement","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('产学研合作情况删除成功');
        $this->redirect('/companys/achievements/'.$_SESSION['companyid']);
    }
    //企业项目跟踪
    function edittrackinfo($flag=null){
        $trackid=$this->Session->read('trackid');
        if(!empty($trackid) && empty($flag)){
            $this->Session->write('trackid',$trackid);
            $this->data=$this->CompTrackinfo->findById($trackid);
        }else{
            if(!empty($this->data)){
                $companyid=$this->Session->read('companyid');
                if($companyid){
                    $this->data["CompTrackinfo"]["cid"]=$companyid;
                }
                $this->CompTrackinfo->save($this->data);
                $pid=$this->data["CompTrackinfo"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompTrackinfo->getLastInsertId();					
                    $data=array("guid"=>$pid,"event"=>"addtrackinfo","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"edittrackinfo","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash('企业项目跟踪成功');
                if(empty($this->data["CompTrackinfo"]["id"])){
                    $trackid=$this->CompTrackinfo->getLastInsertId();
                }else{
                    $trackid=$this->data["CompTrackinfo"]["id"];
                }
                $this->Session->write('trackid',$trackid);
                $this->redirect(array('action' => 'edittrackinfo'));
            }
        }
        $this->set('id',$trackid);
    }
    
    function gettalentcount($compayid)
    {
        $declaretypes=$this->Codetype->getCValues($this->Constant->DeclareType,1);
        $declaretypecount=array();
        $talentcount=0;
        $i=0;
        foreach ($declaretypes as $key=>$declaretype)
        {
            $where="CompTalent.type_id='$key'";
            if($compayid){
                $where.=" and CompTalent.cid='$compayid'";
            }
            $where.=" and CompTalent.is_deleted='0'";
            $count=$this->CompTalent->findCount($where);
            $declaretypecount[$i]["key"]=$key;
            $declaretypecount[$i]["count"]=$count;
            $declaretypecount[$i]["name"]=$declaretype;
            $i++;
            $talentcount+=$count;
        }
        $this->set(compact('declaretypes','declaretypecount','talentcount'));
    }
    
    function talent(){
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);				
        $dstatus=$this->Codetype->getCValues($this->Constant->Declarate_Status,1);
        $compayid=$this->Session->read('companyid');
        //$this->gettalentcount($compayid);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/talent/';
        $urlcount=0;
        $where="";
        $declaretype="";
        if(!empty($_GET['declaretype'])){
            $where.="CompTalent.type_id='".$_GET['declaretype']."' and ";
            $declaretype=$_GET['declaretype'];
        }	
        $where.="(CompTalent.is_deleted='0' and CompTalent.cid = '".$compayid."')";
        $this->CompTalent->unbindModel(array ('hasMany' => array ('Attachment')));
        $urlcount=$this->CompTalent->findCount($where);
        if(!empty($_GET['declaretype'])){
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        $paging['total'] =$urlcount;
        $showpage=0;
        $talents=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompTalent->unbindModel(array ('hasMany' => array ('Attachment')));
            $talents=$this->CompTalent->findAll($where,
            "`Talstack`.`gov`,`CompTalent`.`id`, `CompTalent`.`declare_time`,`CompTalent`.`declare_name`,`CompTalent`.`declarate_status`,`CompTalent`.`type_id`,`CompTalent`.`creater`","CompTalent.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('talents','showpage','declaretype','dstatus','talstacktype'));
    }
    function timetalent()
    {
        $compayid=$this->Session->read('companyid');
        $where="(CompTalent.is_deleted='0' and CompTalent.cid = '".$compayid."')";
        $this->CompTalent->unbindModel(array ('hasMany' => array ('Attachment'),
            'belongsTo' => array ('type_id')));
        $talentcount=$this->CompTalent->findCount($where);
        $this->CompTalent->unbindModel(array ('hasMany' => array ('Attachment'),
            'belongsTo' => array ('type_id')));
        $objyears=$this->CompTalent->findAll($where,"distinct(year(declare_time)) as declare_time","declare_time asc",null,null);
        $declaretypes=$this->Codetype->getCValues($this->Constant->DeclareType,1);
        $i=0;
        foreach ($objyears as $stryear){
            $declare_time=$stryear[0]["declare_time"];
            $wheres=$where." and year(CompTalent.declare_time)='".$declare_time."'";
            $this->CompTalent->unbindModel(array ('hasMany' => array ('Attachment')));
            $objCompTalent=$this->CompTalent->findAll($wheres);
            $objyears[$i]["CompTalent"]=$objCompTalent;
            $objyears[$i][0]["count_declare_time"]=count($objCompTalent);
            $declaretypecount=array();
            $j=0;
            foreach ($declaretypes as $key=>$declaretype)
            {
                $cwhere="CompTalent.type_id='$key' and CompTalent.cid='$compayid'";
                $cwhere.=" and CompTalent.is_deleted='0'";
                $cwhere.=" and year(CompTalent.declare_time)='".$declare_time."'";
                $count=$this->CompTalent->findCount($cwhere);
                $declaretypecount[$j]["key"]=$key;
                $declaretypecount[$j]["count"]=$count;
                $declaretypecount[$j]["name"]=$declaretype;
                $j++;
            }
            $objyears[$i][0]['declaretypecount']=$declaretypecount;
            $i++;
        }
        $this->set(compact('objyears','talentcount'));
    }
    function gettname($super_class){
        $this->layout=null;
        $this->loadModel("Talstack");
        $this->Talstack->unbindModel(array ('belongsTo' => array ('Codevalue')));
        $declaretype=$this->Talstack->getTname($super_class);
        $this->set(compact('declaretype','super_class'));
    }
    function edittalent($id=null){
        
        $filetypes=$this->Codetype->getCValues($this->Constant->Personfile,1);
        //print_r($filetypes);
        $statues=$this->Codetype->getCValues($this->Constant->Declarate_Status);
        $this->loadModel("Talstack");
        $this->Talstack->unbindModel(array ('belongsTo' => array ('Codevalue')));
        $declaretype=$this->Talstack->getTname();
        $this->set(compact('declaretype','filetypes'));
        $attachments=array();
        if($id){
            $objCompTalent=$this->CompTalent->findById($id);	
            $attachments=$objCompTalent["Attachment"];
            $this->data =$objCompTalent;
            $declare_time=$objCompTalent["CompTalent"]["declare_time"];			
            $project_time=$objCompTalent["CompTalent"]["project_time"];
            if($project_time&&$project_time!="0000-00-00"){
                $this->data["CompTalent"]["project_time"]=$project_time;
            }
            else if($project_time=="0000-00-00"){$this->data["CompTalent"]["project_time"]="";}
            else{
                $this->data["CompTalent"]["project_time"]="";
            }
            if($declare_time){
                $this->data["CompTalent"]["declare_time"]=date("Y-m-d",strtotime($declare_time));
            }
        }else{
            if (!empty($this->data)) {
                $user=$this->Session->read('User');
                if(empty($this->data["CompTalent"]["creater"])){
                $this->data["CompTalent"]["creater"] = $user["id"];
                }
                $this->CompTalent->save($this->data);
                $pid=$this->data["CompTalent"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                
                if(empty($this->data["CompTalent"]["project_time"])){
                    $this->data["CompTalent"]["project_time"] =null;
                }	
                if(empty($pid)){
                    $pid=$this->CompTalent->getLastInsertId();						
                    $data=array("guid"=>$pid,"event"=>"addtalent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"edittalent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash('人才项目保存成功');
                $id=$this->CompTalent->id;
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                foreach($filetypes as $key=>$filetype){
                if(!empty($_FILES['upload'.$key])){
                    $uploads=$_FILES['upload'.$key];
                    $name=$_FILES['upload'.$key]['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i]){
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $id;
                            $objAttachment["Attachment"]["cvid"] = $key;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
            }
            $this->redirect('/companys/talent/');
            }
            $this->data["CompTalent"]["public"]=1;
        }
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType);		
        $this->set(compact('attachments','id','statues','talstacktype'));
    }
    function showtalent($id=null){
        $talstack=$this->CompTalent->findById($id);
        $this->edittalent($id);
        $talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);		
        $this->set(compact('taltype','talstacktype','talstack'));
    }
    function deltalent($id){
        $this->CompTalent->id=$id;
        $this->CompTalent->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deltalent","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('人才项目删除成功');
        $this->redirect('/companys/talent/');
    }
    
    //其它项目材料申报情况
    function otherdeclare(){
        $otrdecltype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);	//主管部门
        $dstatus=$this->Codetype->getCValues($this->Constant->Declarate_Status,1);//申报状态
        $compayid=$this->Session->read('companyid');
        //$this->gettalentcount($compayid);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/otherdeclare/';
        $urlcount=0;
        $where="";
//		$declaretype="";
//		if(!empty($_GET['declaretype'])){
//			$where.="CompOtherdeclare.type_id='".$_GET['declaretype']."' and ";
//			$declaretype=$_GET['declaretype'];
//		}	
        $where.="(CompOtherdeclare.is_deleted='0' and CompOtherdeclare.cid = '".$compayid."')";
        $this->CompOtherdeclare->unbindModel(array ('hasMany' => array ('Attachment')));
        $urlcount=$this->CompOtherdeclare->findCount($where);
        if(!empty($_GET['declaretype'])){
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        $paging['total'] =$urlcount;
        $showpage=0;
        $others=array();
        $page="";
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompOtherdeclare->unbindModel(array ('hasMany' => array ('Attachment')));
            $others=$this->CompOtherdeclare->findAll($where,null,"CompOtherdeclare.modified desc",$limit,$page);
            $this->set(compact("page"));
//			debug($page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('others','showpage','dstatus','otrdecltype','page'));
    }
    //其它项目材料申报情况显示
    function showotherdeclare($id=null){
        $otrdecltype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);	//主管部门
        $dstatus=$this->Codetype->getCValues($this->Constant->Declarate_Status,1);//申报状态
        $filetypes=$this->Codetype->getCValues($this->Constant->Otherfile,1);
        $compayid=$this->Session->read('companyid');
        
        $other=$this->CompOtherdeclare->findById($id);
//		$this->editotherdeclare($id);
//		$talstacktype=$this->Codetype->getSubType($this->Constant->TalstackType,"-",1);		
        $this->set(compact('other','otrdecltype','dstatus','filetypes'));
    }
    //其它项目材料申报情况编辑
    function editotherdeclare($id=null){
        $filetypes=$this->Codetype->getCValues($this->Constant->Otherfile,1);
//		print_r($filetypes);
        $dstatus=$this->Codetype->getCValues($this->Constant->Declarate_Status);
//		$this->loadModel("Talstack");
//		$this->Talstack->unbindModel(array ('belongsTo' => array ('Codevalue')));
//		$declaretype=$this->Talstack->getTname();
        $this->set(compact('filetypes'));
        $attachments=array();
        if($id){
            $objOther=$this->CompOtherdeclare->findById($id);	
            $attachments=$objOther["Attachment"];
            $this->data =$objOther;
            $declare_time=$objOther["CompOtherdeclare"]["declare_time"];
            if($declare_time){
                $this->data["CompOtherdeclare"]["declare_time"]=date("Y-m-d",strtotime($declare_time));
            }else{
                $this->data["CompOtherdeclare"]["declare_time"]="";
            }
            $project_time=$objOther["CompOtherdeclare"]["project_time"];
            if($project_time){
                $this->data["CompOtherdeclare"]["project_time"]=date("Y-m-d",strtotime($project_time));
            }else{
                $this->data["CompOtherdeclare"]["project_time"]="";
            }
            $assessment_time=$objOther["CompOtherdeclare"]["assessment_time"];
            if($assessment_time){
                $this->data["CompOtherdeclare"]["assessment_time"]=date("Y-m-d",strtotime($assessment_time));
            }else{
                $this->data["CompOtherdeclare"]["assessment_time"]="";
            }
        }else{
            if (!empty($this->data)) {
                $compayid=$this->Session->read('companyid');
                $this->data["CompOtherdeclare"]["cid"] = $compayid;
                if(empty($this->data["CompOtherdeclare"]["declare_time"])){
                    $this->data["CompOtherdeclare"]["declare_time"] =null;
                }
                if(empty($this->data["CompOtherdeclare"]["project_time"])){
                    $this->data["CompOtherdeclare"]["project_time"] =null;
                }
                if(empty($this->data["CompOtherdeclare"]["assessment_time"])){
                    $this->data["CompOtherdeclare"]["assessment_time"] =null;
                }
                
                $this->CompOtherdeclare->save($this->data);
                $pid=$this->data["CompOtherdeclare"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompOtherdeclare->getLastInsertId();						
                    $data=array("guid"=>$pid,"event"=>"addotherdeclare","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editotherdeclare","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash('项目保存成功');
                $id=$this->CompOtherdeclare->id;
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                foreach($filetypes as $key=>$filetype){
                if(!empty($_FILES['upload'.$key])){
                    $uploads=$_FILES['upload'.$key];
                    $name=$_FILES['upload'.$key]['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i]){
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $id;
                            $objAttachment["Attachment"]["cvid"] = $key;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
            }
            $this->redirect('/companys/otherdeclare/');
            }
//			$this->data["CompOtherdeclare"]["public"]=1;
        }
        $otrdecltype=$this->Codetype->getSubType($this->Constant->TalstackType);		
        $this->set(compact('attachments','id','dstatus','otrdecltype'));
    }
    //其它项目申报情况删除
    function delotherdeclare($id){
        $this->CompOtherdeclare->id=$id;
        $this->CompOtherdeclare->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deltalent","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash('项目删除成功');
        $this->redirect('/companys/otherdeclare/');
    }
    
    //修改密码
    function changepwd() {
       // var_dump($_SESSION['User']['id']);die;
        $userid=$_SESSION['User']['id'];
        if (!empty($this->data)){
            $this->set('user', $this->User->read());
            $user=$this->User->findById($userid);
            
            if ($this->User->validates()){
                
                if(md5($this->data['User']['OldPassword']) != $user['User']['password']){
                    $this->Session->setFlash('原始密码错误','default',array('class' => 'info_error_alert'));
                }else{
                    if (md5($this->data['User']['NewPassword']) != $user['User']['password']){
                  
                        if ($this->data['User']['NewPassword'] == $this->data['User']['RetypePassword']){
                            
                            $this->data['User']['password'] = md5($this->data['User']['NewPassword']);
                          
                            if ($this->User->save($this->data)) {
                                $this->Session->setFlash('密码修改成功');
                                $this->redirect(array('action' => 'index'));
                            }
                        }else{
                            $this->Session->setFlash('确认密码不匹配','default',array('class' => 'info_error_alert'));
                            //$this->data['User']['errormsg']=__("确认密码不匹配",true);
                        }
                    }else{
                       
                        $this->Session->setFlash('新密码不能与原始密码相同','default',array('class' => 'info_error_alert'));
                        //$this->data['User']['errormsg']=__('新密码不能与原始密码相同！',true);
                    }
                }

                
             
               
            }
        }
      // var_dump($userid);
       $objusers=$this->User->findById($userid);
     //   var_dump($objusers);die;
        $this->data=$objusers;
        $this->set(compact('userid'));
    }
    function userinfo() {
//		$this->loadModel("User");
//		$this->loadModel("Group");
//		$user=$this->Session->read('User');
//		$id=$user["id"];
//		$this->User->id = $id;
//		$user = $this->User->read();
//		$groupid = $user['User']['group_id'];
//		$photo_id = $user['User']['photo_id'];
//		$this->set('attachment',$this->Attachment->findById($photo_id));
//		$this->set('group',$this->Group->findById($groupid));
//		$this->set('user', $this->User->read());
//		$firstuser = $this->User->find('first', array('order' => array('User.created'),'conditions' => array('User.isadmin' => 1,'User.is_deleted' => 0)));
//		$this->set(compact('firstuser','id'));
    }
    
    //显示载体租赁的信息
    function carrierlease()
    {
        $forbids=$this->Codetype->getCValues($this->Constant->Forbid);//入驻划区
        $carrierleases = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/carrierlease/';
        $urlcount=0;
        
        //$where="(CompCarrierlease.is_deleted='0')";	
        $where = "CompCarrierlease.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompCarrierlease.cid='$compayid'";
        }
        $urlcount = $this->CompCarrierlease->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompFinanc->unbindModel(array ('hasMany' => array ('Attachment')));
            $carrierleases=$this->CompCarrierlease->findAll($where,null, "CompCarrierlease.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('carrierleases','showpage',"forbids"));
    }
    
    //添加和编辑载体租赁的信息
    function editcarrierlease($id=null)
    {
        $forbids=$this->Codetype->getCValues($this->Constant->Forbid);
        $this->set(compact('id','forbids'));
        if($id){
            //编辑，如果没有数据就在页面上载入原来要被编辑的信息
            if(empty($this->data))
            {
                $this->CompCarrierlease->id = $id;
                $carrierlease = $this->CompCarrierlease->read();
                $this->data = $carrierlease;
                $this->data["CompCarrierlease"]["deadline"] = date("Y-m-d",strtotime($carrierlease["CompCarrierlease"]["deadline"]));
                $this->data["CompCarrierlease"]["starttime"] = date("Y-m-d",strtotime($carrierlease["CompCarrierlease"]["starttime"]));
            }
        }else{
                if(!empty($this->data))
                {
                        if(empty($this->data["CompCarrierlease"]["area"]))
                        {
                            $this->data["CompCarrierlease"]["area"] = 0;
                        }
                        if(empty($this->data["CompCarrierlease"]["rent"]))
                        {
                            $this->data["CompCarrierlease"]["rent"] = 0;
                        }
                        $carrier_id=$this->data["CompCarrierlease"]["id"];
                        if(empty($carrier_id))
                        {
                            $user = $this->Session->read("User");
                            $this->data["CompCarrierlease"]["creater"] = $user["id"];
                        }
                        $this->CompCarrierlease->save($this->data);					
                        $pid=$this->data["CompCarrierlease"]["id"];
                        App::import('Helper', 'Accp');
                        $accp = new AccpHelper();
                        if(empty($pid)){
                            $pid=$this->CompCarrierlease->getLastInsertId();					
                            $data=array("guid"=>$pid,"event"=>"addcarrierlease","usertype"=>"1");
                            $isflag=$accp->accpalert($data);
                        }else{					
                            $data=array("guid"=>$pid,"event"=>"editcarrierlease","usertype"=>"1");
                            $isflag=$accp->accpalert($data);				
                        }
                        $this->Session->setFlash('载体租赁信息保存成功');
                        $this->redirect(array('action' => 'showcarrierlease',$this->CompCarrierlease->id));
                }
        }
       
    }
    
    function delcarrierlease($id)
    {
        $this->CompCarrierlease->id = $id;
        $this->CompCarrierlease->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delcarrierlease","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("载体租赁删除成功");
        $this->redirect(array('action'=>'carrierlease'));
    }
    
    function showcarrierlease($id=null)
    {
        $forbids=$this->Codetype->getCValues($this->Constant->Forbid);//入驻划区
        $this->CompCarrierlease->id = $id;
        $carrierlease= $this->CompCarrierlease->read();
        $this->set(compact('carrierlease','company','forbids'));
    }
    
    //显示宿舍租赁信息
    function dormitorylease()
    {
        $dormitoryleases = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/dormitorylease/';
        $urlcount=0;
            
        $where = "CompDormitorylease.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompDormitorylease.cid='$compayid'";
        }
        $urlcount = $this->CompDormitorylease->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompDormitorylease->unbindModel(array ('hasMany' => array ('Attachment')));
            $dormitoryleases=$this->CompDormitorylease->findAll($where,null, "CompDormitorylease.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('dormitoryleases','showpage'));
    }
    
    function showdormitorylease($id)
    {
        $this->CompDormitorylease->id = $id;
        $dormitorylease= $this->CompDormitorylease->read();
        $this->set(compact('dormitorylease','company'));
    }
    
    function editdormitorylease($id = null)
    { 
        $this->set(compact('id'));
            if($id)
            {
                if(empty($this->data))
                {
                    $this->CompDormitorylease->id = $id;
                    $dormitory = $this->CompDormitorylease->read();
                    $this->data = $dormitory;
                    $this->data["CompDormitorylease"]["starttime"] = date("Y-m-d",strtotime($dormitory["CompDormitorylease"]["starttime"]));
                    $this->data["CompDormitorylease"]["deadline"] = date("Y-m-d",strtotime($dormitory["CompDormitorylease"]["deadline"]));
                }
            }
            else 
            {
                    if(!empty($this->data))
                    {
                            if(empty($this->data["CompDormitorylease"]["area"]))
                            {
                                $this->data["CompDormitorylease"]["area"] = 0;
                            }
                            if(empty($this->data["CompDormitorylease"]["rent"]))
                            {
                                $this->data["CompDormitorylease"]["rent"] = 0;
                            }
                            $user = $this->Session->read("User");
                            $this->data["CompDormitorylease"]["creater"] = $user["id"];
                            $this->CompDormitorylease->save($this->data);
                            $pid=$this->data["CompDormitorylease"]["id"];
                            App::import('Helper', 'Accp');
                            $accp = new AccpHelper();
                            if(empty($pid)){
                                $pid=$this->CompDormitorylease->getLastInsertId();						
                                $data=array("guid"=>$pid,"event"=>"adddormitorylease","usertype"=>"1");
                                $isflag=$accp->accpalert($data);
                            }else{					
                                $data=array("guid"=>$pid,"event"=>"editdormitorylease","usertype"=>"1");
                                $isflag=$accp->accpalert($data);				
                            }
                            $this->Session->setFlash('宿舍租赁信息保存成功');
                            $this->redirect(array('action' => 'showdormitorylease',$this->CompDormitorylease->id));
                    }
            }
    }
    
    function deldormitorylease($id)
    {
        $this->CompDormitorylease->id = $id;
        $this->CompDormitorylease->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deldormitorylease","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("宿舍租赁删除成功");
        $this->redirect(array('action'=>'dormitorylease'));
    }
    
    
    //领军人才补贴发放信息
    function learentbonus()
    {
        $learentbonuses = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/learentbonus/';
        $urlcount=0;
            
        $where = "CompLearentbonus.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompLearentbonus.cid='$compayid'";
        }
        $urlcount = $this->CompLearentbonus->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompLearentbonus->unbindModel(array ('hasMany' => array ('Attachment')));
            $learentbonuses=$this->CompLearentbonus->findAll($where,null, "CompLearentbonus.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('learentbonuses','showpage'));
    }
    
    function editlearentbonus($id = null)
    {
        $this->set(compact('id'));
           if($id)
            {
                if(empty($this->data))
                {
                    $this->CompLearentbonus->id = $id;
                    $learentbonus = $this->CompLearentbonus->read();
                    $this->data = $learentbonus;
                    $this->data["CompLearentbonus"]["date"] = date("Y-m-d",strtotime($learentbonus["CompLearentbonus"]["date"]));
                }
            }
            else 
            {
                    if(!empty($this->data))
                    {
                            $this->CompLearentbonus->save($this->data);
                            $pid=$this->data["CompLearentbonus"]["id"];
                            App::import('Helper', 'Accp');
                            $accp = new AccpHelper();
                            if(empty($pid)){
                                $pid=$this->CompLearentbonus->getLastInsertId();						
                                $data=array("guid"=>$pid,"event"=>"addlearentbonus","usertype"=>"1");
                                $isflag=$accp->accpalert($data);
                            }else{					
                                $data=array("guid"=>$pid,"event"=>"editlearentbonus","usertype"=>"1");
                                $isflag=$accp->accpalert($data);				
                            }
                            $this->Session->setFlash('领军人才津贴发放信息保存成功');
                            $this->redirect(array('action' => 'showlearentbonus',$this->CompLearentbonus->id));
                    }
            }
    }
    
    function showlearentbonus($id = null)
    {
        $this->CompLearentbonus->id = $id;
        $learentbonus= $this->CompLearentbonus->read();
        $this->set(compact('learentbonus','company'));
    }
    
    function dellearentbonus($id)
    {
        $this->CompLearentbonus->id = $id;
        $this->CompLearentbonus->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"dellearentbonus","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("领军人才津贴发放信息删除成功");
        $this->redirect(array('action'=>'learentbonus'));
    }
    
    //研究院人才津贴发放信息
    function researchrentbonus()
    {
        $researchrentbonuses = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/researchrentbonus/';
        $urlcount=0;
            
        $where = "CompResearchrentbonus.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompResearchrentbonus.cid='$compayid'";
        }
        $urlcount = $this->CompResearchrentbonus->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $this->CompResearchrentbonus->unbindModel(array ('hasMany' => array ('Attachment')));
            $researchrentbonuses=$this->CompResearchrentbonus->findAll($where,null, "CompResearchrentbonus.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('researchrentbonuses','showpage'));
    }
    
    function editresearchrentbonus($id = null)
    {
        $this->set(compact('id'));
           if($id)
            {
                if(empty($this->data))
                {
                    $this->CompResearchrentbonus->id = $id;
                    $researchrentbonus = $this->CompResearchrentbonus->read();
                    $this->data = $researchrentbonus;
                    $this->data["CompResearchrentbonus"]["date"] = date("Y-m-d",strtotime($researchrentbonus["CompResearchrentbonus"]["date"]));
                }
            }
            else 
            {
                    if(!empty($this->data))
                    {
                            $this->CompResearchrentbonus->save($this->data);
                            $pid=$this->data["CompResearchrentbonus"]["id"];
                            App::import('Helper', 'Accp');
                            $accp = new AccpHelper();
                            if(empty($pid)){
                                $pid=$this->CompResearchrentbonus->getLastInsertId();					
                                $data=array("guid"=>$pid,"event"=>"addresearchrentbonus","usertype"=>"1");
                                $isflag=$accp->accpalert($data);
                            }else{					
                                $data=array("guid"=>$pid,"event"=>"editresearchrentbonus","usertype"=>"1");
                                $isflag=$accp->accpalert($data);				
                            }
                            $this->Session->setFlash('研究院人才津贴发放信息保存成功');
                            $this->redirect(array('action' => 'showresearchrentbonus',$this->CompResearchrentbonus->id));
                    }
            }
    }
    
    function showresearchrentbonus($id = null)
    {
        $this->CompResearchrentbonus->id = $id;
        $researchrentbonus= $this->CompResearchrentbonus->read();
        $this->set(compact('researchrentbonus'));
    }
    
    function delresearchrentbonus($id = null)
    {
        $this->CompResearchrentbonus->id = $id;
        $this->CompResearchrentbonus->saveField("is_deleted","1");		
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delresearchrentbonus","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("研究院人才津贴发放信息删除成功");
        $this->redirect(array('action'=>'researchrentbonus'));
    }
       

    
    //企业人才招聘信息
    function applyjob()
    {
        $applyjobs = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/applyjob/';
        $urlcount=0;
            
        $where = "CompJobapply.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompJobapply.cid='$compayid'";
        }
        $urlcount = $this->CompJobapply->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $applyjobs=$this->CompJobapply->findAll($where,null, "CompJobapply.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('applyjobs','showpage'));
    }
    
    function editapplyjob($id = null)
    {
        $this->set(compact('id'));
        if($id)
        {
            if(empty($this->data))
            {
                $this->CompJobapply->id = $id;
                $jobapplies = $this->CompJobapply->read();
                $this->data = $jobapplies;
                $this->data["CompJobapply"]["releasedate"] = date("Y-m-d",strtotime($jobapplies["CompJobapply"]["releasedate"]));
            }
        }
        else 
        {
            if(!empty($this->data))
            {
                    $this->CompJobapply->save($this->data);
                    $pid=$this->data["CompJobapply"]["id"];
                        App::import('Helper', 'Accp');
                        $accp = new AccpHelper();
                        if(empty($pid)){
                            $pid=$this->CompJobapply->getLastInsertId();					
                            $data=array("guid"=>$pid,"event"=>"addapplyjob","usertype"=>"1");
                            $isflag=$accp->accpalert($data);
                        }else{					
                            $data=array("guid"=>$pid,"event"=>"editapplyjob","usertype"=>"1");
                            $isflag=$accp->accpalert($data);				
                        }
                    $this->Session->setFlash('企业人才需求信息保存成功');
                    $this->redirect(array('action' => 'showapplyjob',$this->CompJobapply->id));
            }
        }
    }
    
    function showapplyjob($id)
    {
        $this->CompJobapply->id = $id;
        $applyjobs= $this->CompJobapply->read();
        $this->set(compact('applyjobs'));
    }
    
    function delapplyjob($id)
    {
        $this->CompJobapply->id = $id;
        $this->CompJobapply->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delapplyjob","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("企业人才需求信息删除成功");
        $this->redirect(array('action'=>'applyjob'));
    }
    
    //企业金融发布信息
    function finacerelease(){
        $finacereleases = array();
        $compayid = $this->Session->read('companyid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/finacerelease/';
        $urlcount=0;
            
        $where = "CompFinacerelease.is_deleted='0'";
        if($compayid)
        {
            $where.="and CompFinacerelease.cid='$compayid'";
        }
        $urlcount = $this->CompFinacerelease->findCount($where);
        
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $finacereleases=$this->CompFinacerelease->findAll($where,null, "CompFinacerelease.modified desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        
        $this->set(compact('finacereleases','showpage'));
    }
    
    function editfinacerelease($id=null)
    {
        if($id)
        {
            if(empty($this->data))
            {
                $this->CompFinacerelease->id = $id;
                $finacereleases = $this->CompFinacerelease->read();
                $this->data = $finacereleases;
            }
        }
        else 
        {
            if(!empty($this->data))
            {
                    $this->CompFinacerelease->save($this->data);
                    $pid=$this->data["CompFinacerelease"]["id"];
                        App::import('Helper', 'Accp');
                        $accp = new AccpHelper();
                        if(empty($pid)){
                            $pid=$this->CompFinacerelease->getLastInsertId();					
                            $data=array("guid"=>$pid,"event"=>"addfinacerelease","usertype"=>"1");
                            $isflag=$accp->accpalert($data);
                        }else{					
                            $data=array("guid"=>$pid,"event"=>"editfinacerelease","usertype"=>"1");
                            $isflag=$accp->accpalert($data);				
                        }
                    $this->Session->setFlash('企业金融发布信息保存成功');
                    $this->redirect(array('action' => 'showfinacerelease',$this->CompFinacerelease->id));
            }
        }
        $this->set(compact('id'));
    }
    
    function showfinacerelease($id)
    {
        $this->CompFinacerelease->id = $id;
        $finacereleases= $this->CompFinacerelease->read();
        $this->set(compact('finacereleases'));
    }
    
    function delfinacerelease($id)
    {
        $this->CompFinacerelease->id = $id;
        $this->CompFinacerelease->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delfinacerelease","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("企业金融发布信息删除成功");
        $this->redirect(array('action'=>'finacerelease'));
    }
    
    function demand(){
        $compayid = $this->Session->read('companyid');								
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/companys/demand/';
        $urlcount=0;
        $where="";		
        $where.="CompDemand.is_deleted='0'"; 
        if($compayid)
            {
                $where.="and CompDemand.cid='$compayid'";
            }	    							
        $urlcount = $this->CompDemand->findCount($where);
        $paging['total'] =$urlcount;
        $showpage=0;
        $demands=array();
        if ($paging['total'] > 0) {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $demands=$this->CompDemand->findAll($where,
            "`CompDemand`.`id`, `CompDemand`.`title`, `CompDemand`.`publisher`,`CompDemand`.`validity`,`CompDemand`.`created`",
            "CompDemand.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('demands','showpage'));
    }
        
    function deldemand($id){
        $this->CompDemand->id = $id;
        $this->CompDemand->saveField("is_deleted","1");
        $data=array("guid"=>$id,"event"=>"deldemand","usertype"=>"1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("信息删除成功");
        $this->redirect(array('action'=>'demand'));
    }
    
    function editdemand($id=null){
        $type=$this->Codetype->getCValues($this->Constant->Require_Type);
        $this->set(compact('id','type'));				
          if($id){
            $obj=$this->CompDemand->findById($id);
            $this->data=$obj;	 	
           }
           else{
            if(!empty($this->data)){
                $this->CompDemand->save($this->data);
                $pid=$this->data["CompDemand"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid)){
                    $pid=$this->CompDemand->getLastInsertId();					
                    $data=array("guid"=>$pid,"event"=>"adddemand","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editdemand","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash('信息保存成功');
                $this->redirect(array('action'=>'demand'));
             }		
         }
    }
                
    function showdemand($id)
    {		
        $this->editdemand($id);		
    }
    
    //显示企业的概况
    function overview()
    {
        $compayid = $this->Session->read('companyid');
        
        $objpatent=$this->Codetype->getCValues($this->Constant->PatentType);
        //debug($objpatent);
        $invent="";
        $cinvent=$this->Constant->Invent;
        foreach ($objpatent as $key=>$patent)
        {
            if($patent==$cinvent)
            {
                $invent=$key;
            }
        }	
        
        $this->loadModel("CompOverview");
        $objCompany = $this->CompOverview->findById($compayid);
        $this->set(compact("objCompany","invent"));
        
    }
    
    
    function dourl($userid,$id=null)
    {
        $urlpath = base64_decode($_GET["urlpath"]);
        $userid = base64_decode($userid);
        
        //echo "urlpath".$urlpath."<br/>";
        //echo "userid".$userid."<br/>";
        //echo "id".$id."<br/>";
        
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("userid"=>$userid);
        $logindata=$accp->accplogin($data);
        //print_r($logindata);
        
        if($logindata['result'])
        {
            $this->Session->write('pwd', $this->data['User']['password']);
            $this->Session->write('User', $logindata);
            
            $data=array("isadmin"=>"1","userid"=>"0","usertype"=>"1");
            $objusers=$accp->accpuser($data);
            $this->Session->write('UserList',$objusers);
            $ccdata=array("isadmin"=>"1","userid"=>"0","usertype"=>"2,3,4,5");
            $allusers=$accp->accpuser($ccdata);
            $this->Session->write('AllUserList',$allusers);
            if(empty($id)){
                $this->redirect($urlpath);
                exit();
            }
            $this->loadModel("SearchCompany");
            $id = base64_decode($id);
            $objcompany=$this->SearchCompany->findById($id,"`SearchCompany`.`company_name`");
            $this->Session->write('companyid', $id);
            $this->Session->write('companyname', $objcompany["SearchCompany"]["company_name"]);
            $where="CompPage.cid='$id' and CompPage.is_deleted='0'";
            $comppage=$this->CompPage->findAll($where,"CompPage.id");
            if($comppage){
                $this->Session->write('cpid', $comppage[0]["CompPage"]["id"]);
            }else{
                $this->Session->write('cpid', '');
            }
            $where="CompTrackinfo.cid='$id'";
            $comptrackinfo=$this->CompTrackinfo->findAll($where,"CompTrackinfo.id");
            if($comptrackinfo){
                $this->Session->write('trackid', $comptrackinfo[0]["CompTrackinfo"]["id"]);
            }else{
                $this->Session->write('trackid', '');
            }
            //print_r($urlpath);
            //exit();
            $this->redirect($urlpath);
        }
    }
    
    
    
    
    
    
    
    //打开页面前执行的方法
    function beforeFilter()
    {
        parent::beforeFilter();
        $language = 'chn';
        $this->Session->write('Config.language', $language);
        $user=$this->Session->read('User');
        if (!$user){
            $isflag=1;
            if($this->action=="dourl"){
                $isflag=0;
            }
            if($isflag){
                $this->redirect('/users/login');
            }
        }else{
            if($user['cid'] && $this->action=="index"){
                $this->redirect('/companys/showinfosummary/'.$user['cid']);
                exit();
            }
        }
    }
    //打开页面后执行的方法
    function afterFilter()
    {
        
    }
    
    function get_img(){
    	$filepath = base64_decode($_GET['path']);
    	
    	header("Pragma: public");		
		header("Content-type: application/octet-stream");
		header("Content-Disposition: attachment; filename=\"111\"");
		$filecontent = file_get_contents($filepath);
		echo $filecontent;
		exit;
    }

    
}
?>